为什么我的 Laravel 队列作业在 60 秒后失败?

Why are my Laravel Queue Jobs failing after 60 seconds?

情况

我正在使用 Laravel 队列来处理大量媒体文件,单个作业预计需要几分钟(假设最多一个小时)。

我正在使用 Supervisor 运行 我的队列,并且我一次 运行ning 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

有一些奇怪的地方我不知道如何解释或更正:

  1. 我的作业在 运行ning 60 到 65 秒后一直失败。
  2. 在被标记为失败后,作业 继续 运行 即使在被标记为失败后也是如此。最终他们确实最终成功解决了。
  3. 当我找到问题的原因时,它成功了。

我坚信这是超时问题;但是,我的印象是 --timeout=0 会导致无限超时。

问题

如何防止这种临时的 "failure" 作业状态?是否还有其他我不知道的可能会调用队列超时的地方?

原来在config/queue.php

里除了timeout还有一个expire设置定义
    'database' => [
        'driver' => 'database',
        'table' => 'jobs',
        'queue' => 'default',
        'expire' => 60,
    ],

将其更改为更高的值就可以了。


更新: 此参数现在称为 retry_after

    'database' => [
        'driver' => 'database',
        'table' => 'jobs',
        'queue' => 'default',
        'retry_after' => 60,
    ],

重要说明:"expire" 现在称为 "retry_after" (Laravel 5.4)

这会起作用

php artisan queue:listen --timeout=1200

根据需要调整时间

就我而言,我使用的是 Symfony\Component\Process\Process。我也必须如下设置超时。

$process = new Process([...]);
$process->setTimeout(null);