My webapp has a ton of jobs, all running well, exept one.
I need this particular job to survive a long time, a whole hour, 3600 seconds, and fails if over time, and do not retry.
I tried to setup this property in my job
public $timeout = 3600;
public $retryAfter = 4000;
public $tries = 1;
I obtained that after the fail this particula job is never retried, and it’s ok.
But timeout and/or retryAfter are ignored. The job is marked as failed after a few minutes.
What am I doing wrong?
Also, please, what is the differene from timeout and retryAftrer ?!?
More info about my context
My queue is managed by supervisor as follows:
[program:projectname-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/appdemo.projectname.com/artisan queue:work redis --sleep=3 --tries=3
autostart=true
autorestart=true
user=www-data
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/appdemo.projectname.com/storage/logs/laravel_worker.log
This is the suggested configurations as per Lararavel’s documentation.
2
Answers
public $timeout = 3600
will work only if you are running your queue withqueue:work
, but will not work if you usequeue:listen
.Also, on
worker
level you have--timeout
parameter where you can specify timeout on worker level, not just on job level, like thisphp artisan queue:work --timeout=3600
.However, you should definitely consider having a separate queue for the jobs that are time consuming, so that job should be queued on another queue, but all other not time consuming jobs can run on the one queue.
https://laravel.com/docs/7.x/queues#customizing-the-queue-and-connection
Also,
timeout
defines for how long that job should be running, andretryAfter
specifies after how much time it should try to run it again. Of coursetries
needs to be set to higher value, so it could retry.Hope this helps.
A long running job may have several factors playing into why it fails early:
Take a look into each of these to see where your bottleneck may be. Bear in mind, setups will vary from server to server.