Laravel - Job has been attempted too many times or run too long - Solved

By Hardik Savani November 5, 2023 Category : Laravel

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...

Tags :
Shares