Skip to content

Commit d8ab94a

Browse files
committed
🐛 polling options constructor accepts values
1 parent 57ec68c commit d8ab94a

2 files changed

Lines changed: 35 additions & 26 deletions

File tree

src/ClientOptions/PollingOptions.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,25 @@ class PollingOptions
3030

3131
/**
3232
* Polling Options.
33+
*
34+
* @param float $initialDelaySec Initial delay (in seconds) before attempting to poll a queue.
35+
* @param float $delaySec Delay (in seconds) between successive attempts to poll a queue.
36+
* @param integer $maxRetries Maximum number of retries for a queue.
37+
* @throws MindeeApiException Throws if any delay value is below the allowed minimum.
3338
*/
34-
public function __construct()
39+
public function __construct(float $initialDelaySec = 2.0, float $delaySec = 1.5, int $maxRetries = 80)
3540
{
36-
$this->initialDelaySec = 2.0;
37-
$this->delaySec = 1.5;
38-
$this->maxRetries = 80;
41+
$this->setInitialDelaySec($initialDelaySec);
42+
$this->setDelaySec($delaySec);
43+
$this->setMaxRetries($maxRetries);
3944
}
4045

4146
/**
42-
* @param integer $initialDelay Delay between polls.
47+
* @param float $initialDelay Delay between polls.
4348
* @return $this
44-
* @throws MindeeApiException Throws if the initial parsing delay is less than 4 seconds.
49+
* @throws MindeeApiException Throws if the initial parsing delay is less than the minimum.
4550
*/
46-
public function setInitialDelaySec(int $initialDelay): self
51+
public function setInitialDelaySec(float $initialDelay): self
4752
{
4853
if ($initialDelay < MINIMUM_INITIAL_DELAY_SECONDS) {
4954
throw new MindeeApiException(
@@ -56,11 +61,11 @@ public function setInitialDelaySec(int $initialDelay): self
5661
}
5762

5863
/**
59-
* @param integer $delay Delay between successive attempts to poll a queue.
64+
* @param float $delay Delay between successive attempts to poll a queue.
6065
* @return $this
6166
* @throws MindeeApiException Throws if the delay is too low.
6267
*/
63-
public function setDelaySec(int $delay): self
68+
public function setDelaySec(float $delay): self
6469
{
6570
if ($delay < MINIMUM_DELAY_SECONDS) {
6671
throw new MindeeApiException(
@@ -78,7 +83,7 @@ public function setDelaySec(int $delay): self
7883
*/
7984
public function setMaxRetries(int $maxRetries): self
8085
{
81-
if (!$maxRetries || $maxRetries < 0) {
86+
if ($maxRetries <= 0) {
8287
$this->maxRetries = 80;
8388
error_log("Notice: setting the amount of retries for auto-parsing to 80.");
8489
} else {

tests/V2/ClientV2TestFunctional.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace V2;
66

7+
use Mindee\ClientOptions\PollingOptions;
78
use Mindee\Input\PathInput;
89
use Mindee\Input\UrlInputSource;
910
use Mindee\V2\Client;
@@ -29,9 +30,12 @@ protected function setUp(): void
2930
public function testParseFileEmptyMultiPageMustSucceed(): void
3031
{
3132
$source = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/multipage_cut-2.pdf');
32-
$inferenceParams = new ExtractionParameters($this->modelId, rag: false, rawText: true);
33+
$modelParams = new ExtractionParameters($this->modelId, rag: false, rawText: true);
34+
$pollingOptions = new PollingOptions(maxRetries: 100);
3335

34-
$response = $this->mindeeClient->enqueueAndGetResult(ExtractionResponse::class, $source, $inferenceParams);
36+
$response = $this->mindeeClient->enqueueAndGetResult(
37+
ExtractionResponse::class, $source, $modelParams, $pollingOptions
38+
);
3539
self::assertNotNull($response);
3640
$inference = $response->inference;
3741
self::assertNotNull($inference);
@@ -67,9 +71,9 @@ public function testParseFileFilledSinglePageMustSucceed(): void
6771
TestingUtilities::getV1DataDir() . '/products/financial_document/default_sample.jpg'
6872
);
6973

70-
$inferenceParams = new ExtractionParameters($this->modelId, rag: false, textContext: 'this is an invoice');
74+
$modelParams = new ExtractionParameters($this->modelId, rag: false, textContext: 'this is an invoice');
7175

72-
$response = $this->mindeeClient->enqueueAndGetResult(ExtractionResponse::class, $source, $inferenceParams);
76+
$response = $this->mindeeClient->enqueueAndGetResult(ExtractionResponse::class, $source, $modelParams);
7377
self::assertNotNull($response);
7478
$inference = $response->inference;
7579
self::assertNotNull($inference);
@@ -100,10 +104,10 @@ public function testInvalidUUIDMustThrowError(): void
100104

101105
$source = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf');
102106

103-
$inferenceParams = new ExtractionParameters('INVALID MODEL ID');
107+
$modelParams = new ExtractionParameters('INVALID MODEL ID');
104108

105109
try {
106-
$this->mindeeClient->enqueue($source, $inferenceParams);
110+
$this->mindeeClient->enqueue($source, $modelParams);
107111
} catch (MindeeV2HttpException $e) {
108112
self::assertStringStartsWith('422-', $e->errorCode);
109113
self::assertNotEmpty($e->title);
@@ -115,10 +119,10 @@ public function testUnknownModelMustThrowError(): void
115119
{
116120
$source = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/multipage_cut-2.pdf');
117121

118-
$inferenceParams = new ExtractionParameters('fc405e37-4ba4-4d03-aeba-533a8d1f0f21', textContext: 'this is invalid');
122+
$modelParams = new ExtractionParameters('fc405e37-4ba4-4d03-aeba-533a8d1f0f21', textContext: 'this is invalid');
119123

120124
try {
121-
$this->mindeeClient->enqueue($source, $inferenceParams);
125+
$this->mindeeClient->enqueue($source, $modelParams);
122126
} catch (MindeeV2HttpException $e) {
123127
self::assertStringStartsWith('404-', $e->errorCode);
124128
self::assertNotEmpty($e->title);
@@ -142,7 +146,7 @@ public function testInvalidWebhookIDsMustThrowError(): void
142146
{
143147
$source = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/multipage_cut-2.pdf');
144148

145-
$inferenceParams = new ExtractionParameters(
149+
$modelParams = new ExtractionParameters(
146150
$this->modelId,
147151
null,
148152
null,
@@ -154,7 +158,7 @@ public function testInvalidWebhookIDsMustThrowError(): void
154158
);
155159

156160
try {
157-
$this->mindeeClient->enqueue($source, $inferenceParams);
161+
$this->mindeeClient->enqueue($source, $modelParams);
158162
} catch (MindeeV2HttpException $e) {
159163
self::assertStringStartsWith('422-', $e->errorCode);
160164
self::assertNotEmpty($e->title);
@@ -166,9 +170,9 @@ public function testUrlInputSourceMustNotRaiseErrors(): void
166170
{
167171
$urlSource = new UrlInputSource(getenv('MINDEE_V2_SE_TESTS_BLANK_PDF_URL'));
168172

169-
$inferenceParams = new ExtractionParameters($this->modelId);
173+
$modelParams = new ExtractionParameters($this->modelId);
170174

171-
$response = $this->mindeeClient->enqueueAndGetResult(ExtractionResponse::class, $urlSource, $inferenceParams);
175+
$response = $this->mindeeClient->enqueueAndGetResult(ExtractionResponse::class, $urlSource, $modelParams);
172176
self::assertNotNull($response);
173177
$inference = $response->inference;
174178
self::assertNotNull($inference);
@@ -190,9 +194,9 @@ public function testDataSchemaMustSucceed(): void
190194
TestingUtilities::getV2DataDir() . '/products/extraction/data_schema_replace_param.json'
191195
);
192196

193-
$inferenceParams = new ExtractionParameters($this->modelId, dataSchema: $dataSchemaReplace);
197+
$modelParams = new ExtractionParameters($this->modelId, dataSchema: $dataSchemaReplace);
194198

195-
$response = $this->mindeeClient->enqueueAndGetResult(ExtractionResponse::class, $source, $inferenceParams);
199+
$response = $this->mindeeClient->enqueueAndGetResult(ExtractionResponse::class, $source, $modelParams);
196200
self::assertNotNull($response);
197201
$inference = $response->inference;
198202
self::assertNotNull($inference);
@@ -225,13 +229,13 @@ public function testMultipleWebhooksMustSucceed(): void
225229
TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf'
226230
);
227231

228-
$inferenceParams = new ExtractionParameters(
232+
$modelParams = new ExtractionParameters(
229233
$this->modelId,
230234
webhookIds: [
231235
getenv('MINDEE_V2_FAILURE_WEBHOOK_ID'),
232236
getenv('MINDEE_V2_SE_TESTS_FAILURE_WEBHOOK_ID')]
233237
);
234-
$response = $this->mindeeClient->enqueue($source, $inferenceParams);
238+
$response = $this->mindeeClient->enqueue($source, $modelParams);
235239
self::assertCount(2, $response->job->webhooks);
236240
}
237241
}

0 commit comments

Comments
 (0)