Skip to content

Instantly share code, notes, and snippets.

@eddiefisher
Forked from wbotelhos/clear-sidekiq-jobs.sh
Last active July 10, 2024 11:01
Show Gist options
  • Save eddiefisher/c19697481788763e883b31f9461760ec to your computer and use it in GitHub Desktop.
Save eddiefisher/c19697481788763e883b31f9461760ec to your computer and use it in GitHub Desktop.
Clear Sidekiq Jobs
# 1. Clear retry set
Sidekiq::RetrySet.new.clear
# 2. Clear scheduled jobs
Sidekiq::ScheduledSet.new.clear
# 3. Clear 'Processed' and 'Failed' jobs
Sidekiq::Stats.new.reset
# 3. Clear 'Dead' jobs statistics
Sidekiq::DeadSet.new.clear
# Via API
require 'sidekiq/api'
stats = Sidekiq::Stats.new
stats.queues
# {"production_mailers"=>25, "production_default"=>1}
queue = Sidekiq::Queue.new('queue_name')
queue.count
queue.clear
https://stackoverflow.com/questions/69617976/how-to-query-sidekiq-queues-by-job-class-queue-name-and-arguments
def in_queues?(job_class, queue_name, arguments = [])
Sidekiq::Queue.new(queue_name).any? do |job|
job_class == job.klass && job.args == arguments
end
end
# FOR BUSY JOBS
# take the process_id from the /busy page in sidekiq and kill the longest running one.
workers = Sidekiq::Workers.new
long_process_id = 'integration.3:4:71111aaa111' # Eg: 'integration.3:4:71d1d7f4ef5a'
workers.each do |process_id, thread_id, work|
process = Sidekiq::Process.new('identity' => process_id)
process.stop! if process_id == long_process_id
end
# FOR SCHEDULED JOBS
# you need to know the jid to make this happen
jid = 'scheduled111aaa222' # Eg: 'e460064eda529b97e93314d4'
job = Sidekiq::ScheduledSet.new.find_job(jid)
job.delete # will just remove the job
# FOR RETRY JOBS
# you need to know the jid to make this happen
jid = 'retry111aaa222aaa' # Eg: 'e460064eda529b97e93314d4'
job = Sidekiq::RetrySet.new.find_job(jid)
job.delete # will just remove the job
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment