10

I am using the Sidekiq Gem with Rails 3. Is there a way to see if the sidekiq workers are ready to process jobs? We want to make sure that stuff is not just getting enqueued and sitting there. I tried something like this...

stats = Sidekiq::Stats.new
puts stats.queues

But that will always return default => 0, if redis is up, even if sidekiq is not ready to process jobs.

HelloWorld
  • 4,251
  • 8
  • 36
  • 60

3 Answers3

5

You can access the Sidekiq Workers API to access the active set of workers:

worker_api = Sidekiq::Workers.new
worker_api.size
 => 1
worker_api.each {|worker| do_stuf(worker) }

The simplest solution would be to access the API and wait until the expected number of worker processes are up and running via the size attribute of the Worker API.

Winfield
  • 18,985
  • 3
  • 52
  • 65
  • I have Sidekiq up and running, but this method is still returning `0` for me. – stephen.hanson May 27 '15 at 16:29
  • 1
    Something is broken about your environment. Either the environment your Sidekiq client API loaded in isn't connecting to the same Redis sidekiq database as the Sidekiq server, or the server did not actually come up successfully and register itself in Redis. For example, if you were running a Sidekiq server in production Rails env but API client in development env (different redis DBs). – Winfield May 27 '15 at 20:29
  • 3
    Just to note that you first need to `require sidekiq/api` to get access to `Sidekiq::Workers`. And I would also suggest that `Sidekiq::ProcessSet.new.size` is more useful for judging if Sidekiq is up, because `Sidekiq::Workers` only refers to currently running jobs rather than whether Sidekiq itself is simply listening. – tombh Jun 29 '15 at 23:10
5

First of all, your worker processes should be running. Check this:

ps = Sidekiq::ProcessSet.new
ps.size # => 2
ps.each do |process|
  p process['busy']     # => 3
  p process['hostname'] # => 'myhost.local'
  p process['pid']      # => 16131
end
ps.each(&:quiet!) # equivalent to the USR1 signal
ps.each(&:stop!) # equivalent to the TERM signal

From https://github.com/mperham/sidekiq/wiki/API#processes

So if they do - you can enqueue more work. The only case when tasks can remain in the queue while your worker processes are working is when the worker processes are processing jobs slower than they come in. Then your queue will grow and newly enqueued tasks will not be processed until all previous jobs are done. But this is your responsibility to figure out why your workers performing slowly.

Hope that helps!

pokrovskyy
  • 437
  • 5
  • 8
3

For myself, I prefer to run the following in a console (either on my server or locally):

ps -ef | grep "sidekiq"
craig.kaminsky
  • 5,588
  • 28
  • 31