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
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| laravel/framework:10.0.0 | active | — | — | — |
| laravel/framework:11.0.0 | active | — | — | — |
Root Cause
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.
generic中文
队列作业超过了最大尝试次数(max_attempts),或作业执行时间超过了超时设置(retry_after),导致工作进程在多次重试后将其标记为失败。
Official Documentation
https://laravel.com/docs/11.x/queues#max-attemptsWorkarounds
-
90% success Inspect the failed_jobs table to retrieve the exception message: 'DB::table('failed_jobs')->where('queue', 'default')->get();' then fix the underlying issue (e.g., add error handling in the job's handle() method).
Inspect the failed_jobs table to retrieve the exception message: 'DB::table('failed_jobs')->where('queue', 'default')->get();' then fix the underlying issue (e.g., add error handling in the job's handle() method). -
85% success Increase the job's timeout and retry_after settings appropriately: in the job class, set 'public $timeout = 120;' and in config/queue.php set 'retry_after' => 120, but ensure the job logic is optimized to complete within that window.
Increase the job's timeout and retry_after settings appropriately: in the job class, set 'public $timeout = 120;' and in config/queue.php set 'retry_after' => 120, but ensure the job logic is optimized to complete within that window.
-
80% success If the job is recoverable, manually requeue it using: 'php artisan queue:retry all' or specifically 'php artisan queue:retry <job-id>' after fixing the underlying bug.
If the job is recoverable, manually requeue it using: 'php artisan queue:retry all' or specifically 'php artisan queue:retry <job-id>' after fixing the underlying bug.
中文步骤
检查 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>' 手动重新排队。
Dead Ends
Common approaches that don't work:
-
80% fail
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% fail
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% fail
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.