Prevent your queued jobs from duplicating

Updated: Jan 27, 2020 — 1 min Read#quick-dip #queues

If you notice your jobs run more than once, make sure the retry_after configuration of the queue connection has a larger value than the job/worker timeout. For example: 

'redis' => [
  'retry_after' => 90,
],

If your job takes more than 90 seconds to run, another worker could pick it up while it's still running. Make sure the timeout value is shorter so the job fails before it gets picked up again:

php artisan queue:work --timeout=60

Same for the job-specific timeout:

class MyJob implements ShouldQueue
{
  public $timeout = 70;
}

If you use SQS, the retry_after is identified by the queue's Visibility Timeout.

By Mohamed Said

Hello! I'm a full-stack web developer working at Laravel. In this publication, I share everything I know about Laravel's core, packages, and tools.

You can find me on Twitter and Github.

Join the mailing list

If you like this article, you may want to consider joining the mailing list to receive new content once it is posted.
This site was built using Wink. Follow the RSS Feed.