Last updated

Resque: how to requeue failed jobs

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:

1# Requeue all jobs in the failed queue
2(Resque::Failure.count-1).downto(0).each { |i| Resque::Failure.requeue(i) }
3
4# Clear the failed queue
5Resque::Failure.clear

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

Tags: Ruby resque