Created
January 29, 2021 13:55
-
-
Save camallen/b5b8e0fd6ede8afd6a462878234e4fc6 to your computer and use it in GitHub Desktop.
cleanup failed and retryable sidekiq jobs
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
# NOTE: sidekiq 6+ introduces new `.scan` method on Sets, use this when the version matches | |
# https://github.com/mperham/sidekiq/wiki/API#scan | |
# e.g. rs = Sidekiq::RetrySet.new, rs.scan('string-to-look-for') | |
# ----------------------------------------------------------------------- | |
# remove any old jobs that won't finish and are in the DEAD set / Morgue | |
rs = Sidekiq::RetrySet.new | |
jobs_to_remove_from_retry = rs.select do |job| | |
# 'workflow_attached_image' | |
# 'user_avatar' | |
# 'subject_location' | |
# 'project_attached_image' | |
# 'user_profile_header' | |
job.klass == 'MediumRemovalWorker' && job.args[0].starts_with?('user_profile_header') | |
end | |
jobs_to_remove_from_retry.size | |
jobs_to_remove_from_retry.map(&:delete) | |
# ----------------------------------------------------------------------- | |
# Retry and busted dead jobs that can now finish | |
ds = Sidekiq::DeadSet.new | |
ds.size | |
# get a list of retryable jobs (bug was fixed) | |
retryable_jobs = ds.select do |job| | |
job.klass == 'MediumRemovalWorker' && job.args[0].starts_with?('panoptes-uploads') | |
end | |
retryable_jobs.map(&:retry) | |
# ----------------------------------------------------------------------- | |
# remove any old jobs that won't finish and are in the DEAD set / Morgue | |
ds = Sidekiq::DeadSet.new | |
ds.size | |
# jobs classes to cleanup | |
jobs_to_remove = %w[MediumRemovalWorker SubjectSetSubjectCounterWorker EmailsProjectsExportWorker EmailsUsersExportWorker] | |
removeable_jobs = ds.select { |job| jobs_to_remove.include? job.klass } | |
removeable_jobs.size | |
# remove them | |
removeable_jobs.map(&:delete) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment