How to clear all Sidekiq queues, using the power of emoji

Here at Honeybadger, we use Sidekiq a lot, and it's great. But there's one problem I've often run into. see, I don't typically run Sidekiq when I'm in development. But in the course of manual testing, I cause lots of jobs to be enqueued. So the next time I do run Sidekiq it tries to process all of those jobs. Not good.

It's easy to find code snippets that will delete the jobs from one Sidekiq queue. But we have lots of queues. I want to clear the jobs from all of them.  After a little digging, I came up with an answer that seems to work well. Behold!

# I originally had a more verbose piece of code here but mperham, Sidekiq's creator, set me straight :)


There are more direct ways to go about it, but this one uses only methods defined in Sidekiq's public API, so hopefully it'll keep working even if the internals change.

Now with more emoji!

If you do a careful reading of the sidekiq source, you may notice you can use the 💣 emoji to invoke the clear method. No joke:


alias_method :💣, :clear

So we can rewrite our "clear all queues" code like so: { |k, v|💣 }

And since emoji's are so cool, we can make our own 💀 method to do the mass deletion.

def 💀 { |queue_name, _|💣 }