Skip to content

Instantly share code, notes, and snippets.

@livoffgrid
Created January 24, 2013 06:10
Show Gist options
  • Select an option

  • Save livoffgrid/4618060 to your computer and use it in GitHub Desktop.

Select an option

Save livoffgrid/4618060 to your computer and use it in GitHub Desktop.
Remove duplicates from Resque::Failure
def remove_duplicates
count = 0
trash = []
failures = Resque::Failure.all(0, -1)
failures.group_by {|f| f['payload']}.each do |k, v|
next unless v.size > 1
trash.concat v[1..-1]
end
trash.map {|f| [failures.index(f), f]}.sort!.each_with_index do |vec, i|
pos = vec[0] - i
f = vec[1]
next unless Resque::Failure.all(pos, 1) == f
count += 1
Resque::Failure.remove(pos)
end
return "Flaged trash: #{trash.size} | Removed from queue: #{count}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment