forked from mindee/mindee-api-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPollingOptions.php
More file actions
87 lines (79 loc) · 2.44 KB
/
PollingOptions.php
File metadata and controls
87 lines (79 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace Mindee\Input;
use Mindee\Error\ErrorCode;
use Mindee\Error\MindeeApiException;
const MINIMUM_INITIAL_DELAY_SECONDS = 1;
const MINIMUM_DELAY_SECONDS = 1;
/**
* Handles options tied to asynchronous parsing.
*/
class PollingOptions
{
/**
* @var integer Initial delay (in seconds) before attempting to poll a queue.
*/
public int $initialDelaySec;
/**
* @var integer Delay (in seconds) between successive attempts to poll a queue.
*/
public int $delaySec;
/**
* @var integer Maximum number of retries for a queue.
*/
public int $maxRetries;
/**
* Polling Options.
*/
public function __construct()
{
$this->initialDelaySec = 2;
$this->delaySec = 1;
$this->maxRetries = 80;
}
/**
* @param integer $initialDelay Delay between polls.
* @return $this
* @throws MindeeApiException Throws if the initial parsing delay is less than 4 seconds.
*/
public function setInitialDelaySec(int $initialDelay): PollingOptions
{
if ($initialDelay < MINIMUM_INITIAL_DELAY_SECONDS) {
throw new MindeeApiException(
"Cannot set initial parsing delay to less than " . MINIMUM_INITIAL_DELAY_SECONDS . " second(s).",
ErrorCode::USER_INPUT_ERROR
);
}
$this->initialDelaySec = $initialDelay;
return $this;
}
/**
* @param integer $delay Delay between successive attempts to poll a queue.
* @return $this
* @throws MindeeApiException Throws if the delay is too low.
*/
public function setDelaySec(int $delay): PollingOptions
{
if ($delay < MINIMUM_DELAY_SECONDS) {
throw new MindeeApiException(
"Cannot set auto-parsing delay to less than " . MINIMUM_DELAY_SECONDS . " second(s).",
ErrorCode::USER_INPUT_ERROR
);
}
$this->delaySec = $delay;
return $this;
}
/**
* @param integer $maxRetries Maximum allowed retries. Will default to 80 if an invalid number is provided.
* @return $this
*/
public function setMaxRetries(int $maxRetries): PollingOptions
{
if (!$maxRetries || $maxRetries < 0) {
$this->maxRetries = 80;
error_log("Notice: setting the amount of retries for auto-parsing to 80.");
} else {
$this->delaySec = $maxRetries;
}
return $this;
}
}