Skip to content

Instantly share code, notes, and snippets.

@KimTrijnh
Forked from mahemoff/uniq.rb
Created July 6, 2020 05:21
Show Gist options
  • Save KimTrijnh/eb2fd0287c21d6e9cf5027e5b810805f to your computer and use it in GitHub Desktop.
Save KimTrijnh/eb2fd0287c21d6e9cf5027e5b810805f 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