Skip to content

ekomobile/retry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Exponential Backoff

Build Status GitHub release Downloads Coverage Maintainability Tech debt

This is a PHP port of https://github.com/cenkalti/backoff (thanks, @cenkalti), which is a port of the exponential backoff algorithm from Google's HTTP Client Library for Java.

Exponential backoff is an algorithm that uses feedback to multiplicatively decrease the rate of some process, in order to gradually find an acceptable rate. The retries exponentially increase and stop increasing when a certain threshold is met.

Examples

Simple

Retry with default exponential backoff.

(new Retry(function () {
    // workload ...
}))();

Advanced

$operation = function () {
  // workload ...
  if ($somePermanentFailCondition) {
    throw new \Ekomobile\Retry\Exception\Permanent(new \Exception('Unretryable error'))
  }
  // ...
  throw new Exception('Retryable error')
};

$backoff = new \Ekomobile\Retry\Backoff\WithMaxRetries(new \Ekomobile\Retry\Backoff\Exponential(), 5);

$notify = function (\Throwable $e) {
  // $logger->log($e);
};

$retry = new \Ekomobile\Retry\Retry($operation, $backoff, $notify);
$retry();