Forked from nisanthchunduru/delete_failed_jobs.rb
Created
September 15, 2022 18:37
-
-
Save latortuga/9608ef2f25a8d49aa04304086adf062a to your computer and use it in GitHub Desktop.
Selectively remove/retry failed jobs in Resque 1.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment