gpt4 book ai didi

php - Laravel 5.2 队列作业不断重试

转载 作者:可可西里 更新时间:2023-11-01 11:24:45 26 4
gpt4 key购买 nike

class ProcessComment extends Job implements ShouldQueue
{
use InteractsWithQueue;

/**
* @var int
*/
public $tries = 1;


public function handle(Somedepency $someDependency) {
// method body....
// tries to connect to a database
// deliberately provide the wrong database url so that the job .
// will throw exception and hence faild
}

问题是当我运行 php artisan queue:work --daemonphp artisan queue:work --daemon --tries=1

tries 选项似乎不起作用。在我的 redis 队列中,我不断地看到它试图做出的尝试。它应该只尝试一次,如果作业失败,则忽略该作业并继续。

"EXEC"
1522044746.165780 [0 172.20.0.5:48992] "WATCH" "queues:comments:reserved"
1522044746.166110 [0 172.20.0.5:48992] "ZRANGEBYSCORE" "queues:comments:reserved" "-inf" "1522044746"
1522044746.166718 [0 172.20.0.5:48992] "UNWATCH"
1522044746.167436 [0 172.20.0.5:48992] "LPOP" "queues:comments"
1522044746.168051 [0 172.20.0.5:48992] "ZADD" "queues:comments:reserved" "1522044806" {"some serialized data here ... "attempts: 4"}

等等

这是我的configs/queue.php

'default' => env('QUEUE_DRIVER', 'redis'),

'connections' => [

'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'comments'
],
],

尝试了很多谷歌,但找不到满意的答案。

谢谢

最佳答案

您需要做的就是添加一个公共(public) $tries 属性,在该数字之后作业将失败。

/**
* The number of times the job may be attempted.
*
* @var int
*/
public $tries = 5;

关于php - Laravel 5.2 队列作业不断重试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49485164/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com