Last Updated | | Ratings | | Unique User Downloads | | Download Rankings |
2021-01-10 (1 month ago) | | Not yet rated by the users | | Total: 40 This week: 2 | | All time: 10,036 This week: 182 |
|
Description | | Author |
This class can be used to run a task and retry while it fails for a period.
It can take as parameter a closure function that executes a given task when it is called.
If the task fails by throwing an exception, this class can retry running that task again after a given period of time.
The class allows configuring the number of times that it will retry running a task that fails, as well the period of time that it waits between two attempts to retry. | |
|
Details
Resilient Task
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.
Usage
Install the `
eshta/resilient-task`
package:
$ composer require eshta/resilient-task
Example
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!');
}
-
try 10 times at most
-
maximum sleep time between retries 16 seconds
-
first sleep time is half a second
-
back-off factor [2 default]: double sleeping time after each failed attempt
Note:: the runner will only stop when there is a non-null result returned by the task, or the max tries have been exhausted
Contributing
See CONTRIBUTING and Code of Conduct,
if you want to make contribution (pull request)
or just build and test project on your own.
Resources
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.