Mig*_*ges 2 laravel laravel-5 laravel-queue laravel-5.5
我需要在侦听器上的特定失败作业之间设置延迟。我知道如果指定选项它的工作原理,但我需要监听器--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');
}
}
Run Code Online (Sandbox Code Playgroud)
您用来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();
}
}
Run Code Online (Sandbox Code Playgroud)
但需要注意的是,输入的值是以秒为单位的延迟时间。因此,如果您想延迟 5 分钟:
$this->release(300);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2157 次 |
最近记录: |