Last active
September 4, 2016 16:45
-
-
Save rah00l/d8e2cc726f701c73dc73e37853b7b01b to your computer and use it in GitHub Desktop.
Script to remove failed / errors from resque
This file contains hidden or 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
## Script to remove failed / errors from resque | |
class RemoveFailedJobs | |
def self.from_resque(offset = 0, limit = 5000, name='Jobs::SampleJob') | |
# Get the number of failed jobs: | |
puts "Total number of failed jobs #{Resque::Failure.count}" | |
# Returns an array of all the failures, paginated | |
all_failures = Resque::Failure.all(offset, limit ) | |
# Collect failures with array index as 'slot' | |
slotted = all_failures.each_with_index { |f_j, i| f_j['slot'] = i } | |
# filter the results as per custom requirement i.e. by provided Job name | |
filtered_jobs = slotted.select { |failed_job| failed_job if failed_job['payload']['class'] == name } | |
# Get the number of failed jobs for 'SampleJob': | |
puts "The number of failed jobs for 'SampleJob' are #{filtered_jobs.count}" | |
# Mandatory to work DOWN from high to low so indices do not shift! | |
ds_product_update_failed_jobs = filtered_jobs.reverse | |
# Removing all errors from SampleJob have been deleted without affecting other Jobs | |
ds_product_update_failed_jobs.each do |j| | |
Resque::Failure.remove( j['slot'] ) | |
end | |
puts "Total number of failed jobs #{Resque::Failure.count}, After removing failed jobs for 'SampleJob'" | |
end | |
end | |
## Run by below command | |
## RemoveFailedJobs.from_resque |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment