简体   繁体   English

Laravel 排队的作业在失败时不会重试

[英]Laravel queued jobs are not retrying when they fail

The problem问题

I'm dispatching a job to execute an action that needs a resource ready to be correctly executed, so if it fails it needs to be retried after some time.我正在调度一个作业来执行一个需要准备好正确执行资源的操作,所以如果它失败了,它需要在一段时间后重试。 But what really happens is that if it fails, it's not executed ever again.但真正发生的是,如果它失败了,它就不会再次执行。 I'm using Supervisor to manage the queue and the database driver and I have changed nothing in my default queue.php config file.我正在使用 Supervisor 来管理队列和数据库驱动程序,并且我的默认queue.php配置文件中没有任何更改。

Using Laravel 5.8.使用 Laravel 5.8。

What I've tried我试过的

I've already tried to manually set the number of tries inside the job class like我已经尝试手动设置作业 class 中的尝试次数,例如

    public $tries = 5; 

and also the same thing with retry delay with重试延迟也是一样的

    public $retryAfter = 60;

My code我的代码

I'm implementing this job based on the default job template made with make:job, and my constructor and handle methods look like this:我正在根据使用 make:job 制作的默认作业模板来实现这项作业,我的构造函数和句柄方法如下所示:

    public function __construct($event, $data)
    {
        $this->event = $event;
        $this->data = $data;
    }

    public function handle()
    {
        Log::info('Job started | ' . $this->event . ' | Attempt: ' . $this->attempts());
        
        // Executes some logic and throws an Exception if it fails

        Log::info('Job succeeded | ' . $this->event);
    }

Finally it doesn't reach "job succeeded" log and doesn't log any other attempt other than 1.最后,它没有达到“作业成功”日志,也没有记录除 1 之外的任何其他尝试。

Is there some concept I'm missing or is this code wrong somehow?是否有一些我遗漏的概念或者这段代码以某种方式错误?

That was a very stupid problem actually.这实际上是一个非常愚蠢的问题。 But if anyone is as dumb as me ever, I'll let the solution here.但是,如果有人像我一样愚蠢,我会让解决方案在这里。

In my queue.php default driver was set as sync which causes the program to just run the job handle method but it does not queue it, 'cause as I've said I didn't change anything.在我的队列中。php默认驱动程序设置为同步,这会导致程序只运行作业句柄方法,但它不会排队,因为我说过我没有改变任何东西。 So I just set it as database and it was fixed.所以我只是将它设置为数据库并且它是固定的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM