Sidekiq Enterprise includes support for unique jobs. Unique jobs are defined with an option in the worker class:
# app/workers/my_worker.rb
class MyWorker
include Sidekiq::Worker
sidekiq_options unique_for: 10.minutes
def perform(...)
end
end
They must be enabled in the Sidekiq initializer as well:
# config/initializers/sidekiq.rb
Sidekiq::Enterprise.unique! unless Rails.env.test?
The time window only applies while the job is running, e.g., if it is unique for 10 minutes and the job completes in 6 minutes then Sidekiq will immediately allow another job to be enqueued; you don't have to wait 4 more minutes for the uniqueness lock to be dropped.
The uniqueness constraint is enforced across all Sidekiq Enterprise nodes.
You may need to adjust your retries
options because a failed job will continue to hold the lock for as long as it is in a retry state. (even if it is not actively executing)