为什么我的 Laravel 队列作业在 60 秒后失败?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34487186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why are my Laravel Queue Jobs failing after 60 seconds?
提问by slifty
The Situation
情况
I'm using Laravel Queues to process large numbers of media files, an individual job is expected to take minutes (lets just say up to an hour).
我正在使用 Laravel 队列处理大量媒体文件,预计单个作业需要几分钟(可以说最多一个小时)。
I am using Supervisor to run my queue, and I am running 20 processes at a time. My supervisor config file looks like this:
我正在使用 Supervisor 来运行我的队列,并且我一次运行 20 个进程。我的主管配置文件如下所示:
[program:duplitron-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/duplitron/artisan queue:listen database --timeout=0 --memory=500 --tries=1
autostart=true
autorestart=true
user=duplitron
numprocs=20
redirect_stderr=true
stdout_logfile=/var/www/duplitron/storage/logs/duplitron-worker.log
There are a few oddities that I don't know how to explain or correct:
有一些奇怪的地方我不知道如何解释或更正:
- My jobs fairly consistently fail after running for 60 to 65 seconds.
- After being marked as failed the job continues to runeven after being marked as failed. Eventually they do end up resolving successfully.
- When I run the failed task in isolationto find the cause of the issue it succeeds just fine.
- 我的作业在运行 60 到 65 秒后总是失败。
- 在被标记为失败后,即使被标记为失败,该作业仍继续运行。最终他们确实最终成功解决。
- 当我单独运行失败的任务以找到问题的原因时,它会成功。
I strongly believe this is a timeout issue; however, I was under the impression that --timeout=0
would result in an unlimited timeout.
我坚信这是一个超时问题;但是,我的印象是--timeout=0
会导致无限超时。
The Question
问题
How can I prevent this temporary "failure" job state? Are there other places where a queue timeout might be invoked that I'm not aware of?
如何防止这种暂时的“失败”工作状态?是否还有其他我不知道的可能会调用队列超时的地方?
回答by slifty
It turns out that in addition to timeout there is an expire
setting defined in config/queue.php
事实证明,除了超时之外,还有一个expire
设置定义在config/queue.php
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'expire' => 60,
],
Changing that to a higher value did the trick.
将其更改为更高的值即可解决问题。
回答by David Vielhuber
Important note: "expire" is now called "retry_after" (Laravel 5.4)
重要说明:“过期”现在称为“retry_after”(Laravel 5.4)
回答by Munna Khan
This will work
这将工作
php artisan queue:listen --timeout=1200
Adjust the time based on your need
根据您的需要调整时间