Laravel Queues in Action (2nd edition) is now available!

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 find this content useful, consider sponsoring me on GitHub.

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 former Laravel core team member & VP of Engineering at Foodics. 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.