Skip to content

Commit

Permalink
fix(cts): add waitForTask helpers tests [skip-bc] (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#3618

Co-authored-by: algolia-bot <accounts+algolia-api-client-bot@algolia.com>
Co-authored-by: Pierre Millot <pierre.millot@algolia.com>
  • Loading branch information
algolia-bot and millotp committed Sep 2, 2024
1 parent 4e47888 commit 20ddbc1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lib/Api/SearchClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Algolia\AlgoliaSearch\Model\Search\DeleteByParams;
use Algolia\AlgoliaSearch\Model\Search\DictionarySettingsParams;
use Algolia\AlgoliaSearch\Model\Search\GetObjectsParams;
use Algolia\AlgoliaSearch\Model\Search\GetTaskResponse;
use Algolia\AlgoliaSearch\Model\Search\IndexSettings;
use Algolia\AlgoliaSearch\Model\Search\OperationIndexParams;
use Algolia\AlgoliaSearch\Model\Search\Rule;
Expand Down Expand Up @@ -2762,6 +2763,8 @@ public function updateApiKey($key, $apiKey, $requestOptions = [])
* @param null|int $maxRetries Maximum number of retries
* @param null|int $timeout Timeout
*
* @return GetTaskResponse
*
* @throws ExceededRetriesException
*/
public function waitForTask($indexName, $taskId, $requestOptions = [], $maxRetries = null, $timeout = null)
Expand All @@ -2774,7 +2777,7 @@ public function waitForTask($indexName, $taskId, $requestOptions = [], $maxRetri
$maxRetries = $this->config->getDefaultMaxRetries();
}

Helpers::retryUntil(
return Helpers::retryUntil(
$this,
'getTask',
[$indexName, $taskId, $requestOptions],
Expand All @@ -2792,6 +2795,8 @@ function ($res) {return 'published' === $res['status']; },
* @param null|int $maxRetries Maximum number of retries
* @param null|int $timeout Timeout
*
* @return GetTaskResponse
*
* @throws ExceededRetriesException
*/
public function waitForAppTask($taskId, $requestOptions = [], $maxRetries = null, $timeout = null)
Expand All @@ -2804,7 +2809,7 @@ public function waitForAppTask($taskId, $requestOptions = [], $maxRetries = null
$maxRetries = $this->config->getDefaultMaxRetries();
}

Helpers::retryUntil(
return Helpers::retryUntil(
$this,
'getAppTask',
[$taskId, $requestOptions],
Expand Down
6 changes: 4 additions & 2 deletions lib/Support/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public static function json_decode($json, $assoc = false, $depth = 512)
* @param int $timeout Timeout
* @param string $timeoutCalculation name of the method to call to calculate the timeout
*
* @return object the last result of the function
*
* @throws ExceededRetriesException
*/
public static function retryUntil(
Expand All @@ -103,11 +105,11 @@ public static function retryUntil(
$res = call_user_func_array([$object, $function], $args);

if ($validate($res)) {
return;
return $res;
}
} catch (\Exception $e) {
// if the task is interrupted, just return
return;
return null;
}

++$retry;
Expand Down

0 comments on commit 20ddbc1

Please sign in to comment.