Created
September 12, 2014 00:29
-
-
Save mahemoff/bf419c568c525f0af903 to your computer and use it in GitHub Desktop.
Ensure Sidekiq jobs are unique (if the queue contains several jobs with same class and args, this will delete all but one of them)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.uniq! queue_name | |
seen_already = Set.new | |
Sidekiq::Queue.new(queue_name).each { |job| | |
key = { job.klass => job.args } | |
key.in?(seen_already) ? job.delete : seen_already << key | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment