Re-Queue failed jobs with Resque

I have been working with resque for about 1-2 months now, while migrating an application from rails 2 to rails 3, I have switched from Delayed Jobs almost completely.

Sometimes, your workers / jobs fail and you need to re-queue them.

The trick is to requeue the job and remove it from the failed stats, this way, if it will fail again, the next time you re-queue the job will not be executed twice.

Here’s the code (from a rake task I have)

(Resque::Failure.count-1).downto(0).each {|i|
  begin
    Resque::Failure.requeue(i)
    Resque::Failure.remove(i)
  rescue Exception => e
    puts e
  end
}
sleep(5.minutes)

I have this rake running every X minutes and requeing failed tasks. If a task keeps failing, then I can check the code in depth and check what the problem is, but sometimes it’s just failing due to HTTP error or something else not related to the code.

Hope this helps.

Drop me a line if it does or you have questions and comments.

<img src="http://feeds.feedburner.com/~r/KensoDev-en/~4/0Evw5H5RV3A" height="1" width="1"/>
Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com