Skip to content

Instantly share code, notes, and snippets.

@wbotelhos
Last active September 30, 2024 01:46
Show Gist options
  • Save wbotelhos/fb865fba2b4f3518c8e533c7487d5354 to your computer and use it in GitHub Desktop.
Save wbotelhos/fb865fba2b4f3518c8e533c7487d5354 to your computer and use it in GitHub Desktop.
Clear Sidekiq Jobs
require 'sidekiq/api'
# 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
# Stats
stats = Sidekiq::Stats.new
stats.queues
# {"production_mailers"=>25, "production_default"=>1}
# Queue
queue = Sidekiq::Queue.new('queue_name')
queue.count
queue.clear
queue.each { |job| job.item } # hash content
# Redis Acess
Sidekiq.redis { |redis| redis.keys }
# ["stat:queues"...
@DaniPB
Copy link

DaniPB commented May 26, 2020

Hi @wbotelhos

Thanks for answer!

I'm using rspec-sidekiq and i can do jobs expectations, nevertheless, when I clear the scheduled jobs with Sidekiq::RetrySet, they still scheduled, and this is why:

image

I'm trying with this Sidekiq::Testing.disable! but for me is not a good idea and anyway is not working yet.

@wbotelhos
Copy link
Author

I see @DaniPB,

Maybe you can mock Redis and do the chances there, if Sidekiq writes there.

https://github.com/sds/mock_redis
https://github.com/guilleiguaran/fakeredis

@DaniPB
Copy link

DaniPB commented May 27, 2020

Yes! @wbotelhos that's a good idea
I was doing something wrong with Sidekiq::Testing.disable! i fixed and now works

image

Thanks a lot for u help!

@wbotelhos
Copy link
Author

Great, @DaniPB! 👏

I loved your editor hearts ^^

@DaniPB
Copy link

DaniPB commented May 27, 2020

Great, @DaniPB!

I loved your editor hearts ^^

@wbotelhos

Thank you!

It's my cute vim config heh!

@fedgut
Copy link

fedgut commented Mar 18, 2021

This is amazing! thank you

@mfalgorepublic
Copy link

thank you !

@daiyan71
Copy link

It was very helpful. Thanks a a lot.

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