Illuminate\Queue\MaxAttemptsExceededException:App\Jobs\ProcessVideo 已被尝试太多次或运行时间过长。该作业可能之前已超时。
Illuminate\Queue\MaxAttemptsExceededException: App\Jobs\ProcessVideo has been attempted too many times or run too long. The job may have previously timed out.
ID: php/laravel-queue-worker-timeout
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| laravel/framework:10.0.0 | active | — | — | — |
| laravel/framework:11.0.0 | active | — | — | — |
根因分析
队列作业超过了最大尝试次数(max_attempts),或作业执行时间超过了超时设置(retry_after),导致工作进程在多次重试后将其标记为失败。
English
A queued job has exceeded the maximum number of attempts (max_attempts) or the job's execution time exceeded the timeout setting (retry_after), causing the worker to mark it as failed after repeated retries.
官方文档
https://laravel.com/docs/11.x/queues#max-attempts解决方案
-
检查 failed_jobs 表以获取异常消息:'DB::table('failed_jobs')->where('queue', 'default')->get();' 然后修复根本问题(例如,在作业的 handle() 方法中添加错误处理)。 -
适当增加作业的超时和 retry_after 设置:在作业类中设置 'public $timeout = 120;',在 config/queue.php 中设置 'retry_after' => 120,但确保作业逻辑优化以在该时间窗口内完成。
-
如果作业可恢复,在修复底层错误后,使用 'php artisan queue:retry all' 或 'php artisan queue:retry <job-id>' 手动重新排队。
无效尝试
常见但无效的做法:
-
80% 失败
Simply increasing the $tries property on the job class to a very high number (e.g., 100) without addressing the underlying timeout or error condition causes the job to keep retrying indefinitely, consuming queue resources and delaying other jobs.
-
60% 失败
Setting retry_after to an extremely high value in config/queue.php (e.g., 3600 seconds) prevents the job from being retried quickly, but if the job is genuinely stuck (e.g., due to an infinite loop), it will still hold the worker slot for too long.
-
90% 失败
Restarting the queue worker with 'php artisan queue:restart' resets the worker but does not clear the failed job status; the job will still be marked as failed in the jobs table and won't be re-executed automatically.