Giter Club home page Giter Club logo

resilient-task's Introduction

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

resilient-task's People

Contributors

0mars avatar yanis-git avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.