daalvand/retry-policy

此包用于执行高可靠性的作业

1.0.3 2021-09-24 09:33 UTC

This package is auto-updated.

Last update: 2024-09-24 16:23:16 UTC


README

  • 此包用于执行高可靠性的作业

安装

安装包

运行composer require daalvand/retry-policy

发布提供者

Laravel

  • php artisan vendor:publish --provider="Daalvand\RetryPolicy\RetryPolicyServiceProvider"

Lumen

  • 将服务提供者添加到bootstrap/app.php文件中
<?php
//...
/** @var App $app */
$app->register(Daalvand\RetryPolicy\RetryPolicyServiceProvider::class);

将配置文件从/vendor/daalvand/retry-policy/src/config复制到config目录。然后在/bootstrap/app.php文件中配置它

<?php
/** @var App $app */
$app->configure("retry-policy");

运行php artisan migrate来迁移失败的作业表

用法

示例

  • Retryable abstract扩展你的可重试类
<?php
use \Daalvand\RetryPolicy\Contracts\Retryable;
//Custom Class
class CustomRetryable extends Retryable
{
    public function execute() : bool
    {
        // TODO: Implement execute() method.
    }
}

#### Create an object from custom retryable
use Daalvand\RetryPolicy\Facades\RetryContext;
$retryable = new CustomRetryable();
$retryable
->setMaxRequeue(20)
->setMaxRetry(2)
->setRetryDelay(10)
->setRqueueDelay(3600);

//retry retryables
RetryContext::perform([$retryable]);

对于将失败的重复尝试消费到流式传输器,运行以下命令

retry_policy:consumer

对于从失败的作业表中重新排队,将以下命令添加到kernel.phpos crontab

retry_policy:requeue

`

活动图

alt Activity Diagram