Created
January 24, 2013 06:10
-
-
Save livoffgrid/4618060 to your computer and use it in GitHub Desktop.
Remove duplicates from Resque::Failure
This file contains hidden or 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 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