Resilient Task Runner, A circuit breaker implementation in PHP, highly configurable task runner with number of max tries, back-off factor, maximum sleep time, and starting sleep time.
Resilient Task Runner, A circuit breaker implementation, highly configurable task runner with number of max retries, back-off factor, maximum sleep time, and starting sleep time.
Install the eshta/resilient-task
package:
$ composer require eshta/resilient-task
use GuzzleHttp\Exception\ConnectException;
$task = function() {
try {
$response = $client->request('GET', 'https://github.com/_abc_123_404');
return $response;
} catch (ConnectException $e) {
echo Psr7\str($e->getRequest());
}
};
$runner = new ResilientTaskRunner(10, 16, 0.5);
$response = $runner->run($task);
if (is_null($response)) {
throw new MyFavouriteException('Service call failed!');
}
Note:: the runner will only stop when there is a non-null result returned by the task, or the max tries have been exhausted
See CONTRIBUTING and Code of Conduct,
if you want to make contribution (pull request)
or just build and test project on your own.