我有一份这样的工作:
//Run very intensive script that generates files
//Notify the user that the job is done
我知道脚本需要 4-5 分钟才能运行,因为这是生成所有文件所需的时间。 然而,正好在 60 秒后,作业被删除 (即我在
jobs
数据库表中没有看到它) 并且用户得到通知。然后,每隔 60 秒,直到脚本完成,用户会收到作业已完成的通知。 这项工作不会失败。该作业仅在前 60 秒内出现在
jobs
表中。文件生成脚本只运行一次。我使用主管:
[program:queue]
process_name=%(program_name)s_%(process_num)02d
command=php artisan queue:work --timeout=600 --queue=high,low
user=forge
numprocs=8
directory=/home/forge/default
stdout_logfile=/home/forge/default/storage/logs/supervisor.log
redirect_stderr=true
这是我的数据库配置:
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'low',
'expire' => 600,
],
如果我使用 redis,行为是一样的
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => 'low',
'expire' => 600,
],
最佳答案
您的配置略有偏差。我不确定 expire
来自哪里,但我相信你的意思是 retry_after
。由于您的配置没有在 key 后定义 retry_after
,Laravel 默认值为 60 秒。因此,您的队列在运行 60 秒后正在终止该作业,并将其重新排队以重试。
此外,以下注释是 from the documentation :
The
--timeout
value should always be at least several seconds shorter than yourretry_after
configuration value. This will ensure that a worker processing a given job is always killed before the job is retried. If your--timeout
option is longer than yourretry_after
configuration value, your jobs may be processed twice.
因此,如果您的队列工作超时将是 600,我建议您将 retry_after 设置为至少 610。
关于Laravel 队列在 60 秒后重新启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42582026/