Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there console commands to look at whats in the queue and to clear the queue in Sidekiq?

I'm used to using delayed_jobs method of going into the console to see whats in the queue, and the ease of clearing the queue when needed. Are there similar commands in Sidekiq for this? Thanks!

like image 593
perseverance Avatar asked Oct 02 '12 01:10

perseverance


People also ask

How do I run Sidekiq worker from console?

To run sidekiq, you will need to open a terminal, navigate to your application's directory, and start the sidekiq process, exactly as you would start a web server for the application itself. When the command executes you will see a message that sidekiq has started.

What is Sidekiq pro?

Sidekiq Pro uses Redis's RPOPLPUSH command to ensure that jobs will not be lost if the process crashes or gets a KILL signal. The Sidekiq Pro client can withstand transient Redis outages or timeouts. It will enqueue jobs locally upon error and attempt to deliver those jobs once connectivity is restored.


2 Answers

There is an ergonomic API for viewing and managing queues.

It is not required by default.

require 'sidekiq/api' 

Here's the excerpt:

# get a handle to the default queue default_queue = Sidekiq::Queue.new   # get a handle to the mailer queue mailer_queue = Sidekiq::Queue.new("mailer")   # How many jobs are in the default queue? default_queue.size # => 1001  # How many jobs are in the mailer queue? mailer_queue.size # => 50  #Deletes all Jobs in a Queue, by removing the queue.     default_queue.clear 

You can also get some summary statistics.

stats = Sidekiq::Stats.new  # Get the number of jobs that have been processed. stats.processed # => 100  # Get the number of jobs that have failed.     stats.failed # => 3  # Get the queues with name and number enqueued. stats.queues # => { "default" => 1001, "email" => 50 }  #Gets the number of jobs enqueued in all queues (does NOT include retries and scheduled jobs). stats.enqueued # => 1051  
like image 119
mkirk Avatar answered Oct 18 '22 00:10

mkirk


I haven't ever used Sidekiq, so it's possible that there are methods just for viewing the queued jobs, but they would really just be wrappers around Redis commands, since that's basically all Sidekiq (and Resque) is:

# See workers Sidekiq::Client.registered_workers  # See queues Sidekiq::Client.registered_queues  # See all jobs for one queue Sidekiq.redis { |r| r.lrange "queue:app_queue", 0, -1 }  # See all jobs in all queues Sidekiq::Client.registered_queues.each do |q|   Sidekiq.redis { |r| r.lrange "queue:#{q}", 0, -1 } end  # Remove a queue and all of its jobs Sidekiq.redis do |r|    r.srem "queues", "app_queue"   r.del  "queue:app_queue" end 

Unfortunately, removing a specific job is a little more difficult as you'd have to copy its exact value:

# Remove a specific job from a queue Sidekiq.redis { |r| r.lrem "queue:app_queue", -1, "the payload string stored in Redis" } 

You could do all of this even more easily via redis-cli :

$ redis-cli > select 0 # (or whichever namespace Sidekiq is using) > keys * # (just to get an idea of what you're working with) > smembers queues > lrange queues:app_queue 0 -1 > lrem queues:app_queue -1 "payload" 
like image 34
bricker Avatar answered Oct 18 '22 02:10

bricker