Laravel Queue Cheatsheet
Let;s define some of the more confusing configurations in Laravel queue management.
Based on Mohamed Said's video shorts series on queues: https://themsaid.com/explaining-laravel-queue-configuration-keys
- The
queue.redis.retry_afterattribute is for when you don't hear back from a job (it didn't succeed and it didn't fail for N seconds), consider it as failed and retry it again.- This is different from when you set the
$retryAfterpublic property or aretryAfter()method on the job class. Here it means if the job fails, retry it after N seconds.- This is equal to the
--delayflag on thequeue:workcommand itself. --delayin your console command is different than setting the$delaypublic property on the job itself. The$delaypublic property here means each time this job is pushed to the queue, delay processing it for N seconds.
- This is equal to the
- This is different from when you set the
- When you set the
$timeoutpublic property on the job class, you're saying if the job is processing for more than N seconds, kill the worker process and stop processing the job and let it retry again.- This is the same as setting the
--timeoutargument in thequeue:workconsole command.- You should set the
queue.redis.retry_afterconfiguration option to be more than the$timeoutof the job itself or the worker.
- You should set the
$timeoutis different than$timeoutAt.$timeoutAtmeans if the job fails, keep retrying it until the set time.- You can do the same using the
retryUntil()method.
- You can do the same using the
- So even if you have
$triesset and the job fails, the worker will ignore that value and keep retrying the job until the$timeoutAttime regardless of the number of attempts.
- This is the same as setting the
- The
queue.redis.block_forconfiguration says when you open a connection to redis and you can't find any jobs, wait for N seconds at the redis level before sleeping and starting a new loop to check for new jobs again. - The
queue.redis.queueconfiguration tells redis which queues to process jobs form first. So ifqueue.redis.queue = high,lowthen redis will not process jobs from thelowqueue in until thehighqueue is empty. - Setting the
--stop-when-emptyflag on thequeue:workcommand will terminate the worker when there aren't any jobs in the queue left to process. Note: A service like supervisor will restart the process over and over.--stop-when-emptyis useful for example in a Docker container. Start the container when the queue is filled with jobs and the container will process all the jobs in the queue, and when it's finished it will be terminated.
Hope this helps.