Laravel - Job has been attempted too many times or run too long - Solved
Yesterday i was working on my email and chat GPT tasks, it was taking time to send email and generate content from Chat GPT API. so i decided to create Job and setup on Queue. But when i setup queue on server using supervisor. Then i was getting following error:
"App\Jobs\GenerateAIContent has been attempted too many times or run too long. The job may have previously timed out. {"exception":"[object] (Illuminate\\Queue\\MaxAttemptsExceededException(code: 0): App\\Jobs\\GenerateAIContent has been attempted too many times or run too long. The job may have previously timed out. at /home/forge/demo.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:746)"
You can also see on screenshot:
I found out solution from my end. You need to increase timeout, max-time and retry_after for fix the timeout issue.
You can see the following two changes:
Change 1:
Increase timeout and max-time in supervisor config file as like the below:
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /home/forge/app.com/artisan queue:work database --max-time=3600 --timeout=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=forge
numprocs=8
redirect_stderr=true
stdout_logfile=/home/forge/app.com/worker.log
stopwaitsecs=3600
Then you need to restart supervisor:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start laravel-worker:*
Change 2:
Next, you need to change retry_after value more then timeout value configuration in queue.php config file.
...
'database' => [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'retry_after' => 9000,
'after_commit' => false,
],
....
Now, you can check it.
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel Login and Registration using Ajax Tutorial
- Laravel Ajax PUT Request Example Tutorial
- Laravel Ajax GET Request Example Tutorial
- Laravel React JS Image Upload Example
- Laravel 9 Queues: How to Use Queue in Laravel 9?
- How to Get Current Week Records in Laravel?
- Laravel Eloquent whereHas() Condition Example
- How to Image Upload in Laravel Vapor?
- Laravel Sweet Alert Confirm Delete Example
- Laravel Migration Custom Foreign Key Name Example
- Laravel Eloquent updateOrCreate Example
- Laravel Eloquent orderByRaw() Query Example
- Laravel Traits | How to Create Trait in Laravel?