How to clear all the jobs from Sidekiq?
Solution 1
According to this issue on Github: https://github.com/mperham/sidekiq/issues/1732 you now need to
require 'sidekiq/api'
Solution 2
You can do as it says on the issue 1077 or as reported in this blog at noobsippets
Both suggest we do the following, and can be done on rails console:
Sidekiq.redis(&:flushdb)
Caution: This command will clear all redis records. I suggest not using it in production
another approach would be
redis-cli --scan --pattern users: * | xargs redis-cli del
according to this blog
Solution 3
Clear Sidekiq Jobs commands:
require 'sidekiq/api'
# Clear retry set
Sidekiq::RetrySet.new.clear
# Clear scheduled jobs
Sidekiq::ScheduledSet.new.clear
# Clear 'Dead' jobs statistics
Sidekiq::DeadSet.new.clear
# Clear 'Processed' and 'Failed' jobs statistics
Sidekiq::Stats.new.reset
# Clear all queues
Sidekiq::Queue.all.map(&:clear)
# Clear specific queue
stats = Sidekiq::Stats.new
stats.queues
# => {"main_queue"=>25, "my_custom_queue"=>1}
queue = Sidekiq::Queue.new('my_custom_queue')
queue.count
queue.clear
Solution 4
As of latest Sidekiq, just blow it up:
require 'sidekiq/api'
q = Sidekiq::Queue.new
q.💣
Yes, the command to clear all is literally a bomb emoji. Also works for Sidekiq::RetrySet
.
Or if you're no fun you can use q.clear
Solution 5
redis-cli flushdb
You can also use redis-cli flushall
Related videos on Youtube
Comments
-
Can Can over 2 years
I am using sidekiq for background tasks in Rails application. Now the numbers of jobs becomes more, so I want to clear all the jobs. I tried the following command in console
Sidekiq::Queue.new.clear
but it was giving following error.
NameError: uninitialized constant Sidekiq::Queue
How do I clear all the jobs from sidekiq?
-
Benj almost 10 yearstry
include 'sidekiq'
before -
Can Can almost 10 years@BenjaminSinclaire its giving TypeError: wrong argument type String (expected Module)
-
Uri Agassi almost 10 yearstry
require 'sidekiq'
before -
Benj almost 10 yearsI always (really always) confuse include and require :)
-
-
intcreator almost 7 yearsThis appears to reset my authentication on the Rails apps that I'm using (which means I have to copy cookies back into my HTTP client). Is there a way to prevent that?
-
jonathanccalixto almost 7 yearsHello, Brandeamon. Are you using redis to control the session of your project? Because these commands are to "clean" all data stored in redis, it is equivalent to a drop database or drop table in relational databases.
-
codemilan about 6 yearsOMG, what the heck is this ? @Xavier, is there method named .💣, can you please guide me the doc on this method (💣).
-
Modus Tollens about 6 years@codemilan See this blog post: blog.honeybadger.io/…
-
M. Habib about 6 yearsThis should be the accepted answer considering its votes.
-
maurice about 6 yearsThis works more predictably than
redis-cli flushdb
if you are running redis on a separate server from your rails server. I was wondering whyredis-cli flushdb
didn't work until I remembered I needed to include host and port arguments. -
Charles Skariah almost 6 yearsThe problem with this approach is if you are sharing same redis/elasticache across different services, it's gonna clear all the other data in the db as well.
-
Charles Skariah almost 6 yearsThe problem with this approach is if you are sharing same redis/elasticache across different services, it's gonna clear all the other data in the redis db as well.
-
jonathanccalixto almost 6 years@Charles Really, but it has how to clean specific parts of the redis, I will research on the subject and post here. But as I use this only in development, for me the solution resolves. ;)
-
escanxr almost 5 yearsYou can also clear all queues with
Sidekiq::Queue.all.map(&:clear)
... Useful when you sync your locale db with the prod 😅 -
meoww- over 4 yearsThis was the only approach that we found would work for ensuring that all recurring job changes would be picked up. We run this every time we do a build as part of our automated processes. We also have a secured mechanism for accessing this and re-daemonizing Sidekiq via one of our application's APIs (in the case of the need for a hot-reload). As far as this flushing other redis instances, we have a separate instance of redis through docker running exclusively for Sidekiq, so data contamination/loss isn't an issue for our group. Thanks for posting this.
-
Shankar Thyagarajan about 4 yearsI got
invalid byte sequence in US-ASCII (ArgumentError)
on executingq.💣
:/ -
Ankit Deshpande over 3 yearsPlease add a disclaimer, this will flush redis, and clear any other keys present on the redis box
-
r4cc00n over 2 yearsBest answer ever!
-
Toucouleur about 2 yearsI love that code!