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.

Hey! 👋 If you want to receive updates on what I'm up to, I host a newsletter on my website themsaid.com and would love to have you.

You can also follow me on Twitter, I regularly post about all things Laravel including my latest video tutorials and blog posts.

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.

This site was built using Wink. Follow the RSS Feed.