Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if sidekiq is started?

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.

like image 869
HelloWorld Avatar asked Mar 20 '14 17:03

HelloWorld


3 Answers

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.

like image 186
Winfield Avatar answered Oct 18 '22 11:10

Winfield


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!

like image 23
pokrovskyy Avatar answered Oct 18 '22 11:10

pokrovskyy


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

ps -ef | grep "sidekiq"
like image 42
craig.kaminsky Avatar answered Oct 18 '22 12:10

craig.kaminsky