Skip to content

Instantly share code, notes, and snippets.

@Chocksy
Last active September 5, 2025 09:49
Show Gist options
  • Save Chocksy/6dccf8cbc0469404ea1967088f00f132 to your computer and use it in GitHub Desktop.
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
jids = %w[dabd42e29be8ad7125257b5a 803782f0184f9b8bea6b5c98 062c0bcc894957ed6390153b dabd42e29be8ad7125257b5a b4237c6d60b941ecb63b090d d2e16e2106ae971c02cca1eb 82de27e501f0b940c3811331 ac04b64cb3858ad798d8c848 620ed48b2634f835d80f0724 c218d426acae0526a7e4363a 1d77ab3b532cbb3e6218fe2a a0eca27c1fea0c1339425ed5 03b22233173d2f3553ac9383 bc96a9f3067669d7ab636d63 b837583e2f6dc19b7f960094 165a1408490f7bf17f7a5e76 9121bec73711e7e91c3f9783 c9a7d30545a5079e48da518c bcf73e0acd433ba30d583d99 5d63d73213c0f5bd1acff066 74b8cb6ddfe6dfcfa7decf15 86528045efe9df34de4fb19f c82c4664b8d1f41a78ff1c02 5931cb2fb3f39d3ed4f38fd8 d556343052509eaa79e6df5b 93bec1b5f397c43958d17c19 cd5c506b706d64e0dfbea83f f0401b3f4784c739db52c7cf b7b3fbaf16ff58662b8d8e23 c265dd16e117f50e5d69b83e 8ca822e8dc86927d3af6341a 7afc16106ffa601bb60dcebb 474170d63437c4313d318e17 dcf1b2d5664e1fa9fbfa5713 3d2963b4eb71c3caf1021d6d dff192ba777384581b084e36 9469ae65e037cf00acc23bfc 6c5e8138d43cbfdbe36b52ea 5a69991799666307e74a0513 24ed6b26a21a95a4169a648a 75c4a8e41fa3f9aae3b3d296 486849cb2300108b71790e2d 7bc91c2e7ed3a2542e31f422 c0e921852c02117ea2eb3fad 77dac42e82d33aeab98878ec 3b240b0785ca273300ef8f9e 78e267e628ab97c302f30326 e0f2c1459a56ec37a4d731fd 1136390e9537346446f195cb f06f2a9f8bc56151b28c227d a9fd6f3593036710ed8ff127 f91ebca0b2fa4b829c602ce4 f6add6d08d3ea2def256b0ad 30a32a326c059b27526f1f2c 9fe007cb0e7c8b872eccd4ac c5b209dc47aacd9757eb3704 cb9ed8512568e8376a70b15a ece69453678a49743633b82d 0685de1c10fae739415fdfbc 8d2f574b2cf5c55ab41d5817 69179756d55e8423743503b2 a65f1f5d45249eed5af70a90 a076a16f27f84528b06bbcd3 8536c9fe7956cc5c5899cfeb 9129562c601e6f3aa66b5ab9 238a9ea083b913100a7bde18 be203b221ef7f2462e542e3b e7c7a4622750d07c87352e7d 97794333d2d571b55a14d79c 7a49236cf04073250b7c0c71 89685515d095716a307463b1 28b44433a1379f2f7196cdd2 fa57e8933c7e4b5cba8c818b 8c3c43a5677fccaac66317bb 9ee9f1fbeb08eafd70ee3d1a 6fd36776ca9d6283791c7731 3209defea0b9811d79dad1f6 4de6dde34045814e1300ea65 e11dd97e26aed3b1bccfeee6 869f0f9e9a6529472d3760d8 e7f94f221feac4dc42662c87 3a919e7880818e6591fb3b5f f79107acc1ec89c416af2b2b 439f6b47879f5849a29889dc fedf18efa2d39699e9dec3f6 5b0400533364ef15b04126fa 81f2bacd1add107e85cb745c c3f698bfcbe3ec13b46fd936 9e6a324202214b871088fd90 f574901f3d21ce0eee12757e e5b60af953a1bf84934b8c15 52a85399968fd4529bdaaf6a 9feaf6f161556bc9e5621efd 06e2f88d5923164d0d0add85 def3a110858a7acb27437b89 f40b183f94928196a512f5e7 d7cf7c591e56871a1648fc6d e9a1a9e51b9bda16de6414c8 6c06dcf5e03c9b3ed7ac538b eca9fc0999c4237ee15a395b d6a873dfb4b3bbeb11339a62 36cb6ce1d3c8759d1dab04b1 8c29092f14ab9c757e13e630]
jids.each do |jid|
job = Sidekiq::RetrySet.new.find_job(jid)
if job
job.delete
else
puts "jid #{jid} = #{job}" and next
end
end
@patriciojofre
Copy link

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

@Chocksy
Copy link
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

It works! πŸ₯³

@adambair
Copy link

Thanks, gonna give this thing a shot. Appreciated!

@YaEvan
Copy link

YaEvan commented Nov 28, 2022

Thanks

@IvanShamatov
Copy link

nice! helped me as well :)

@bikonchou-jp
Copy link

It works, thanks!

@jeffdill2
Copy link

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

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

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

This saved me! Thank you πŸ™

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