Retry a subset of failed jobs in Resque 1.x
Copy the snippet below and paste it in a rails console
def retry_if(&should_retry)
redis = Resque.redis
(0...Resque::Failure.count).each do |i|
serialized_job = redis.lindex(:failed, i)
job = Resque.decode(serialized_job)
next unless should_retry.(job)
Resque::Failure.requeue(i)
end
end
To retry a subset of failed jobs, say email notifications that have failed because of smtp errors
retry_if do |job|
job['payload']['class'] == 'SendEmailNotifications' && job['exception'] == 'Net::SMTPServerBusy'
end
If you want to skip jobs that have already been retried
retry_if do |job|
if job['payload']['class'] == 'SendEmailNotifications' && job['exception'] == 'Net::SMTPServerBusy'
if !job['retried_at']
next true
end
end
false
end
Written by Nisanth
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#