Skip to content

Instantly share code, notes, and snippets.

@juanger
Created September 19, 2013 00:52
Show Gist options
  • Save juanger/6617834 to your computer and use it in GitHub Desktop.
Save juanger/6617834 to your computer and use it in GitHub Desktop.
Clean Resque failed jobs without loading all of them into memory.
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