PHP Classes

Resilient PHP Task Runner: Run a task and retry while it fails for a period

Recommend this page to a friend!
  Info   View files Documentation   View files View files (13)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 47 This week: 1All time: 10,704 This week: 560Up
Version License PHP version Categories
resilient-task 1.0Custom (specified...5PHP 5, Language
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.

Picture of Omar Shaban
Name: Omar Shaban <contact>
Classes: 3 packages by
Country: Germany Germany
Age: 37
All time rank: 4314229 in Germany Germany
Week rank: 411 Up15 in Germany Germany Up
Innovation award
Innovation award
Nominee: 2x

Documentation

Resilient Task

Build Status CodeCov Release PHPv Downloads

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


  Files folder image Files  
File Role Description
Files folder imagesrc (2 files)
Files folder imagetests (1 file)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file CHANGES.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file CONDUCT.md Data Auxiliary data
Accessible without login Plain text file CONTRIBUTING.md Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file Makefile Data Auxiliary data
Accessible without login Plain text file phpmd.xml Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file ResilientTaskRunner.php Class Class source
  Plain text file RunnerInterface.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file ResilientTaskRunnerTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:47
This week:1
All time:10,704
This week:560Up