keboola / retry
可重复和可重试操作的库
0.5.1
2022-09-13 10:26 UTC
Requires
- php: >=7.1
- psr/log: ^1.1|^2|^3
Requires (Dev)
- keboola/coding-standard: ^7.0
- phpstan/phpstan-shim: ^0.10
- phpunit/phpunit: 7.*
Replaces
This package is auto-updated.
Last update: 2024-09-13 14:54:56 UTC
README
可重复和可重试操作的库。
(从 https://github.com/vkartaviy/retry 分支而来)
以下是一个简单的示例
<?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 });
如果您想提供自己的重试决策方法,可以使用 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 });