Created
September 19, 2013 00:52
-
-
Save juanger/6617834 to your computer and use it in GitHub Desktop.
Clean Resque failed jobs without loading all of them into memory.
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 loop_failed(exception_or_class, from) | |
current_idx = from | |
current = Resque::Failure.all(current_idx) | |
while current | |
if current["exception"] == exception_or_class || current["payload"]["class"] == exception_or_class | |
yield(current_idx, current) | |
else | |
current_idx += 1 | |
end | |
current = Resque::Failure.all(current_idx) | |
end | |
end | |
def remove(exception_or_class, from=0) | |
loop_failed(exception_or_class, from) do |failed_idx, job| | |
Resque::Failure.remove(failed_idx) | |
end | |
end | |
def requeue_and_remove(exception_or_class, from=0) | |
loop_failed(exception_or_class, from) do |failed_idx, job| | |
Resque::Failure.requeue(failed_idx) | |
Resque::Failure.remove(failed_idx) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment