What’s the difference between Laravels QueueShouldBeUnique and QueueMiddlewareWithoutOverlapping?

I have a job that is somehow getting kicked off multiple times. I want the job to kick off once and only once. If any other attempts to run the job while it’s already on the queue, I want those runs to ABORT.

I’ve read the Laravel 8 documentation and can’t figure out if I should use:

I believe the first one aborts subsequent attempts to run the job whereas the second keeps it queued, just makes sure it doesn’t run until the first job is finished. Can anyone confirm?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Confirmed locally by attempting to run multiple instances of the same job in a console window.

Implementing the QueueShouldBeUnique interface in the class of my job means that subsequent attempts are ABORTED.

Whereas adding ->withoutOverlapping() to the end of my job reference in the appconsolekernel.php file simply prevents it from running simultaneously. It does NOT abort the job if one is already running.

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x