-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[8.x] Add ability to dispatch unique jobs (Option 1) #35039
Conversation
Thanks @driesvints, I've updated the formatting based on your comments. 👍 |
I think it'd be simpler if you set a unique param on the job and use it to create the lock. Also you can release the lock inside |
@themsaid, I thought about that but it would be a breaking change if users already have that param set on the job. In that case, we'd have to target master instead of 8x. Definitely seems cleaner though.
I didn't want to mess with the handler code, but if you think that's a better approach, I can update the PR to do that. |
You may call it something like As for the handler, IMO it's fine to modify it for this feature. |
I've opened a new PR with a different implementation/syntax as discussed. |
See also #35042 (alternative)
Motivation:
This PR allows the ability to dispatch unique jobs. So, if a unique job is already dispatched, it will not dispatch another job (with the same key) unless the job has completed processing. See laravel/ideas#2151.
Ping: @themsaid and @royduin
Difference between this PR and
WithoutOverlapping
:The difference between
WithoutOverlapping
and dispatching unique jobs is that theWithoutOverlapping
middleware processes jobs uniquely (meaning two jobs with the same key will not be processed in parallel). However, it does not stop jobs (with the same key) from being enqueued if another such job is already in the queue waiting to be processed.Use Case:
This can be quite useful in scenarios such as search indexing. If a search index job is already enqueued for a resource, you probably don't want another such job to be queued until the previous job has finished processing. Sidekiq Enterprise offers the unique jobs feature as well.
How to Use
It's incredibly easy to use this. If you wish to dispatch a unique job, just chain the
unique
method like so: