Skip to content

Instantly share code, notes, and snippets.

@Chocksy
Last active September 5, 2025 09:49
Show Gist options
  • Select an option

  • Save Chocksy/6dccf8cbc0469404ea1967088f00f132 to your computer and use it in GitHub Desktop.

Select an option

Save Chocksy/6dccf8cbc0469404ea1967088f00f132 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
@patriciojofre
Copy link
Copy Markdown

you saved my life! I used the process.stop! to kill a stuck process

@Chocksy
Copy link
Copy Markdown
Author

Chocksy commented Jul 15, 2022

@patriciojofre haha 🀣 i get back to it each time i need to do this as well πŸ‘

@md-farhan-memon
Copy link
Copy Markdown

It works! πŸ₯³

@adambair
Copy link
Copy Markdown

Thanks, gonna give this thing a shot. Appreciated!

@YaEvan
Copy link
Copy Markdown

YaEvan commented Nov 28, 2022

Thanks

@IvanShamatov
Copy link
Copy Markdown

nice! helped me as well :)

@bikonchou-jp
Copy link
Copy Markdown

It works, thanks!

@jeffdill2
Copy link
Copy Markdown

I'm confused why you'd need to instantiate and loop through all of the workers (for the part specific to busy jobs). πŸ˜•

If you already know the process ID, why wouldn't you just do: Sidekiq::Process.new(identity: 'integration.3:4:71111aaa111').stop!?

@hellosweta
Copy link
Copy Markdown

hellosweta commented Jun 20, 2024

I'm confused why you'd need to instantiate and loop through all of the workers (for the part specific to busy jobs). πŸ˜•

If you already know the process ID, why wouldn't you just do: Sidekiq::Process.new(identity: 'integration.3:4:71111aaa111').stop!?

Had the same q and I just did this and it worked! (instantiated the process and then called stop!)

@jeffdill2
Copy link
Copy Markdown

I'm confused why you'd need to instantiate and loop through all of the workers (for the part specific to busy jobs). πŸ˜•
If you already know the process ID, why wouldn't you just do: Sidekiq::Process.new(identity: 'integration.3:4:71111aaa111').stop!?

Had the same q and I just did this and it worked! (instantiated the process and then called stop!)

Awesome! πŸ˜„

@stevenwanderski
Copy link
Copy Markdown

This saved me! Thank you πŸ™

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment