Selectively remove/retry failed jobs in Resque 1.x
def retry_failed_job_if
redis = Resque.redis
(0...Resque::Failure.count).each do |i|
string = redis.lindex(:failed, i)
break if string.nil?
job = Resque.decode(string)
should_retry_job = yield job
next unless should_retry_job
puts "Retrying job with index #{i}"
Resque::Failure.requeue(i)
end
end
retry_failed_job_if do |job|
job['payload']['class'] == 'MailImport' &&
job['exception'] == 'NoMethodError'
end
def delete_failed_job_if
redis = Resque.redis
(0...Resque::Failure.count).each do |i|
string = redis.lindex(:failed, i)
break if string.nil?
job = Resque.decode(string)
should_delete_job = yield job
next unless should_delete_job
redis.lrem(:failed, 1, string)
redo
end
end
delete_failed_job_if do |job|
job['payload']['class'] == 'SendPushNotification' &&
job['exception'] == 'Pusher::HTTPError'
end