devroom.io/drafts/2010-08-23-resque-how-to-requeue-failed-jobs.md
Ariejan de Vroom dbae98c4c0 Moar updates
2013-03-24 14:27:51 +01:00

1.2 KiB

title kind slug created_at tags
Resque: how to requeue failed jobs article resque-how-to-requeue-failed-jobs 2010-08-23
Ruby
resque

Today I found about 100k Resque jobs in the failed queue. Due to a small error in some user content, those jobs all failed. After fixing the problem, how do you reprocess all those jobs?

Option one: go to the resque-web backend and click retry about 100.000 times.

Option two: do some cool ruby commands. ~ Resque offers you direct access to the failed queue and also provides a method to requeue jobs. How easy can it be, right?

With Resque::Failure.all(0,1) you retrieve the first job from the failed queue. Resque::Failure.all is simply a ruby Array.

To requeue jobs, you can use Resque::Failure.requeue(index) where index corresponds to the index of the job in the Resque::Failure.all Array.

To requeue all jobs in the failed queue, you can simply run the following commands:

:::ruby
# Requeue all jobs in the failed queue
(Resque::Failure.count-1).downto(0).each { |i| Resque::Failure.requeue(i) }

# Clear the failed queue
Resque::Failure.clear

That's all there is to it, really. Happy processing!