Here at Honeybadger, we use Sidekiq a lot, and it's great. But there's one problem I've often run into.

...you 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 :)

Sidekiq::Queue.all.each(&:clear)

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:

# https://github.com/mperham/sidekiq/blob/master/lib/sidekiq/api.rb#L255

alias_method :💣, :clear

So we can rewrite our "clear all queues" code like so:

Sidekiq::Stats.new.queues.each { |k, v| Sidekiq::Queue.new(k).💣 }

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

def 💀
  Sidekiq::Stats.new.queues.each { |queue_name, _| Sidekiq::Queue.new(queue_name).💣 }
end

Get the Honeybadger newsletter

Each month we share news, best practices, and stories from the DevOps & monitoring community—exclusively for developers like you.
    author photo
    Starr Horne

    Starr Horne is a Rubyist and Chief JavaScripter at Honeybadger.io. When she's not neck-deep in other people's bugs, she enjoys making furniture with traditional hand-tools, reading history and brewing beer in her garage in Seattle.

    More articles by Starr Horne
    An advertisement for Honeybadger that reads 'Turn your logs into events.'

    "Splunk-like querying without having to sell my kidneys? nice"

    That’s a direct quote from someone who just saw Honeybadger Insights. It’s a bit like Papertrail or DataDog—but with just the good parts and a reasonable price tag.

    Best of all, Insights logging is available on our free tier as part of a comprehensive monitoring suite including error tracking, uptime monitoring, status pages, and more.

    Start logging for FREE
    Simple 5-minute setup — No credit card required