Skip to content

Instantly share code, notes, and snippets.

@mahemoff
Created September 12, 2014 00:29
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mahemoff/bf419c568c525f0af903 to your computer and use it in GitHub Desktop.
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)
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