netlogix / retry
Retries a specific PHP code fragment.
Installs: 2 314
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Requires
- php: >=8.1
Requires (Dev)
- phpunit/phpunit: ^10.5
README
Retries a specific PHP code fragment (called a "task") as long as the "when"
condition evaluates to true
.
(new \Netlogix\Retry\Retry()) ->when(condition: fn(int $incarnation) => $incarnation < PHP_INT_MAX) ->task(subject: fn () => throw new \RuntimeException('false'));
There is a shorthand method for counting retries and sleeping between attempts with increasing intervals.
(new \Netlogix\Retry\Retry()) /** * http://backoffcalculator.com/?attempts=5&rate=1&interval=0.5 * = (0.5 + 1 + 1.5 + 2.0 + 2.5) seconds * = 7.5 seconds */ ->withExponentialBackoff(retryInterval: 0.5, maxRetries: 5) ->onExceptionsOfType(\Doctrine\DBAL\Exception\DeadlockException::class) ->task(fn () => $dbal->executeQuery($statement));