laravel - 如何在侦听器的失败作业之间延迟
问题描述
我需要在 listeners 上的特定失败作业之间设置延迟。我知道是否指定 onption它的工作原理,但我需要监听--delay=5
器的特定延迟(而不是标准工作)。我尝试将属性放在侦听器上,但不起作用。delay
<?php
namespace Froakie\Listeners;
use Carbon\Carbon;
use Froakie\Events\ExampleEvent;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
/**
* Class ExampleListener
*
* @package Froakie\Listeners
* @author Miguel Borges <miguel.borges@edirectinsure.com>
*/
class ExampleListener implements ShouldQueue
{
use InteractsWithQueue;
/**
* The number of seconds the job can run before timing out.
*
* @var int
*/
public $timeout = 5;
/**
* The number of times the job may be attempted.
*
* @var int
*/
public $tries = 3;
public $delay = 5;
public $seconds;
/**
* Handle the event.
*
* @param \Froakie\Events\ExampleEvent $event
* @throws \Exception
*/
public function handle(ExampleEvent $event)
{
// $this->delay(5);
throw new \Exception('test');
}
}
解决方案
您用于release
延迟重试。例子:
public function handle(ExampleEvent $event)
{
if ($this->attempts() <= $this->tries) {
try {
//Try something
} catch (\Exception $e) {
//Try again later
$this->release($this->delay)
}
} else {
//Force end the job
$this->delete();
}
}
但应注意,输入的值是以秒为单位的延迟时间。因此,如果您想将其延迟 5 分钟:
$this->release(300);
推荐阅读
- angularjs - 简单的 AngularJS 路由示例不起作用
- angular - Angular - 渲染后如何执行代码
- google-chrome - Chromium 调试构建没有 TCMalloc 符号
- c# - IDisposable 对象的 Observable:如何处理上一个值 onNext 和 onComplete?
- r - 每日时间序列分析(周一至周五)
- windows - 通过批处理脚本中的参数调用等待微调器
- kubernetes - 是否可以在同一个路由映射中使用 Ambassador prefix_regex 和 regex_rewrite?
- flutter - flutter : 如何在颤动中更改所选文本的背景颜色
- swift - 带有嵌套枚举的 Swift 枚举,如何从 RawRepresentable 协议的字符串中实现关联值
- r - 我应该如何找到 R 中多个变量之间的相关性?“标准差为 0”错误