I'm currently available for full time hire! Inquire Here

Laravel Queue Cheatsheet

Laravel Queue Cheatsheet


Based on Mohamed Said's video shorts series on queues: https://themsaid.com/explaining-laravel-queue-configuration-keys

  • The queue.redis.retry_after attribute 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 $retryAfter public property or a retryAfter() method on the job class. Here it means if the job fails, retry it after N seconds.
      • This is equal to the --delay flag on the queue:work command itself.
      • --delay in your console command is different than setting the $delay public property on the job itself. The $delay public property here means each time this job is pushed to the queue, delay processing it for N seconds.
  • When you set the $timeout public 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 --timeout argument in the queue:work console command.
      • You should set the queue.redis.retry_after configuration option to be more than the $timeout of the job itself or the worker.
    • $timeout is different than $timeoutAt. $timeoutAt means if the job fails, keep retrying it until the set time.
      • You can do the same using the retryUntil() method.
    • So even if you have $tries set and the job fails, the worker will ignore that value and keep retrying the job until the $timeoutAt time regardless of the number of attempts.
  • The queue.redis.block_for configuration 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.queue configuration tells redis which queues to process jobs form first. So if queue.redis.queue = high,low then redis will not process jobs from the low queue in until the high queue is empty.
  • Setting the --stop-when-empty flag on the queue:work command 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-empty is 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.

Anthony Rappa

By Anthony Rappa

Hello! I'm a full stack developer from Long Island, New York. Working mainly with Laravel, Tailwind, Livewire, and Alpine.js (TALL Stack). I share everything I know about these tools and more, as well as any useful resources I find from the community. You can find me on GitHub and LinkedIn.