keboola/retry

Library for repeatable and retryable operations

Maintainers

Details

github.com/keboola/retry

Source

Issues

Installs: 94 530

Dependents: 14

Suggesters: 0

Security: 0

Stars: 1

Watchers: 6

Forks: 2

Open Issues: 4

pkg:composer/keboola/retry

0.5.1 2022-09-13 10:26 UTC

README

The library for repeatable and retryable operations.
(Forked from https://github.com/vkartaviy/retry)

Build Status

Here is a simple example:

<?php

use Retry\RetryProxy;
use Retry\Policy\SimpleRetryPolicy;
use Retry\BackOff\ExponentialBackOffPolicy;

$retryPolicy = new SimpleRetryPolicy(3);
$backOffPolicy = new ExponentialBackOffPolicy();

$proxy = new RetryProxy($retryPolicy, $backOffPolicy);
$result = $proxy->call(function() {
    // call external service and return result
});

If you want to supply your own retry decider method you can by using the CallableRetryPolicy

<?php

use Retry\RetryProxy;
use Retry\Policy\SimpleRetryPolicy;
use Retry\BackOff\ExponentialBackOffPolicy;

$retryPolicy = new CallableRetryPolicy(function (\Throwable $e) {
    if ($e->getCode() === 200) {
        return false;
    } 
    return true;
});
$proxy = new RetryProxy($retryPolicy, new ExponentialBackOffPolicy());
$result = $proxy->call(function() {
   // call external service and return result
});