eshta / resilient-task
弹性任务执行器,一种断路器实现,高度可配置的任务执行器,具有最大重试次数、退避因子、最大睡眠时间和起始睡眠时间。
1.0.1
2021-06-13 10:40 UTC
Requires
- php: >=7.0
Requires (Dev)
- phpmd/phpmd: ^2.7
- phpunit/phpunit: ^6.0
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2024-09-13 18:12:19 UTC
README
弹性任务执行器,一种断路器实现,高度可配置的任务执行器,具有最大重试次数、退避因子、最大睡眠时间和起始睡眠时间。
使用方法
安装 eshta/resilient-task
包
$ composer require eshta/resilient-task
示例
use GuzzleHttp\Exception\ConnectException; $task = function() { try { $response = $client->request('GET', 'https://github.com/_abc_123_404'); return $response; } catch (ConnectException $e) { echo Psr7\str($e->getRequest()); } }; $runner = new ResilientTaskRunner(10, 16, 0.5); $response = $runner->run($task); if (is_null($response)) { throw new MyFavouriteException('Service call failed!'); }
- 最多尝试10次
- 重试之间的最大睡眠时间为16秒
- 第一次睡眠时间为0.5秒
- 退避因子[2默认值]:每次失败尝试后加倍睡眠时间
注意:执行器仅在任务返回非空结果或最大尝试次数耗尽时停止
贡献
如果您想进行贡献(拉取请求)或仅在您的计算机上构建和测试项目,请参阅CONTRIBUTING和行为准则。