The difference between ShouldBeUnique and WithoutOverlapping in #Laravel queues? 💡
ShouldBeUnique doesn't queue a job when another instance is queued/running. WithoutOverlapping queues the job but checks for uniqueness before processing and can release the job 👌
The WithoutOverlapping middleware can be configured to either not release the job or to release it after some time. You can also customize the lock key ⬇️
laravel.com/docs/11.x/queues#preventing-job-overlaps
Back
•
In response to @pascalbaljet
(somebody on 🦋 asked for examples)
An example of ShouldBeUnique may be generating a report of last year's data. Even if the user clicks multiple times, there's no need to push another job to the queue because the outcome will always be the same.
An example of WithoutOverlapping may be a User model that syncs with a third-party CRM. You only want one job at a time (maybe to prevent hitting API limits) but still want to queue subsequent jobs, as the model has likely changed, and you want to push the latest data to the CRM.