2017 © Pedro Peláez
 

library retry

A generic library to retry an operation in case of an error. You can configure the behavior like the exceptions to retry on.

image

tobion/retry

A generic library to retry an operation in case of an error. You can configure the behavior like the exceptions to retry on.

  • Tuesday, June 9, 2015
  • by Tobion
  • Repository
  • 5 Watchers
  • 8 Stars
  • 10,023 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 2 Versions
  • 8 % Grown

The README.md

Retry

PHP library for retrying code, e.g. HTTP requests or database transactions, in case of failures., (*1)

Build Status, (*2)

Installation

$ composer require tobion/retry

Usage

use Tobion\Retry\Retry;

$callableThatMightFail = function (int $arg1, int $arg2): int {
    if (random_int(1, 2) % 2) {
        throw new \RuntimeException('Sudden error');
    }

    return $arg1 + $arg2;
};

// Allows you to call the callable with parameters and retry its execution in case an exception is thrown.
// You can access the return value of the callable (3 in this case).
$returnValue = Retry::configure()->call($callableThatMightFail, 1, 2);

// By default:
// - The callable is retried twice (i.e. max three executions). If it still fails, the last error is rethrown.
// - Retries have a no delay between them.
// - Every \Throwable will trigger the retry logic, i.e. both \Exception and \Error.
// You can adjust the retry logic like this:
$retryingCallable = Retry::configure()
    ->maxRetries(5)
    ->delayInMs(100)
    ->retryOnSpecificExceptions(\RuntimeException::class) // other failures like \TypeError will not be retried
    ->decorate($callableThatMightFail)
;
$returnValue = $retryingCallable(1, 2);
// $retryingCallable just decorates the original callable and can be used like it.
// To find out how often it had to retry, you can use:
$retryingCallable->getRetries();

Contributing

To run tests:, (*3)

$ composer install
$ vendor/bin/simple-phpunit

The Versions

09/06 2015

dev-overengineer

dev-overengineer https://github.com/Tobion/retry

A generic library to retry an operation in case of an error. You can configure the behavior like the exceptions to retry on.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

retry restart repeat retryable

05/06 2015

dev-master

9999999-dev https://github.com/Tobion/retry

A generic library to retry an operation in case of an error. You can configure the behavior like the exceptions to retry on.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

retry restart repeat retryable