Skip to content

Instantly share code, notes, and snippets.

@fongfan999
Forked from Chocksy/kill_sidekiq_job.rb
Created March 18, 2023 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fongfan999/63a9684807a1780d57a5caa6ae866853 to your computer and use it in GitHub Desktop.
Save fongfan999/63a9684807a1780d57a5caa6ae866853 to your computer and use it in GitHub Desktop.
Kill sidekiq jobs by process id for busy jobs and by jid for other sets.
# 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