Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find Sidekiq is running or not

Tags:

In one of my project i am using Sidekiq

Is there any inbuilt Sidekiq console method/method that helps me to find whether sidekiq is running or not.

My requirement is kind of a pre check condition where if Sidekiq is not running i will raise a error.

I tried using the grep like

'ps -ef | grep sidekiq'  

but it's not solving my purpose.

The method i am looking for should be something like:

Sidekiq.is_running?  

Thanks in advance.

I also Tried

Sidekiq not running

1.9.3p392 :021 > system 'ps aux | grep sidekiq' ankitgupta      6683   0.0  0.0  2432768    600 s001  R+   11:47AM   0:00.00 grep sidekiq ankitgupta      6681   0.0  0.0  2433432    916 s001  S+   11:47AM   0:00.01 sh -c ps aux | grep sidekiq  => true 

Sidekiq is running

1.9.3p392 :022 > system 'ps aux | grep sidekiq' ankitgupta      6725   0.0  0.0  2432768    600 s001  S+   11:57AM   0:00.00 grep sidekiq ankitgupta      6723   0.0  0.0  2433432    916 s001  S+   11:57AM   0:00.00 sh -c ps aux | grep sidekiq ankitgupta      6707   0.0  1.3  3207416 111608 s002  S+   11:56AM   0:07.46 sidekiq 2.11.2 project_name [0 of 25 busy]    => true  

It is always returning true.. I want to catch the process when it runs

like image 332
AnkitG Avatar asked May 07 '13 10:05

AnkitG


People also ask

How do I know if I have Sidekiq?

To test your Sidekiq Worker jobs array, run WorkerNameHere.jobs in terminal and see if it contains your job with your jid. If it does, then it was enqueued in Sidekiq to be run as a job.

How do I run on Sidekiq?

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 a Sidekiq process?

Sidekiq is a framework for background job processing that is very useful for handling expensive computation, emails, and other processes that is better served outside of the main web application.

How do you stop a Sidekiq worker?

In order to restart a Sidekiq worker, the recommended way is to send SIGTERM, which is the signal sent to a process to request its termination, to the worker process with a pre-defined timeout configured, followed by the spawning of a new process.


2 Answers

A little trick:

ps aux | grep '[s]idekiq' 

Hope it works

like image 183
dan Avatar answered Dec 31 '22 08:12

dan


Ideally you can do this directly from ruby itself. Put this in some rake task or standalone script (don't forget to specify Sidekiq connection details)

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

like image 29
pokrovskyy Avatar answered Dec 31 '22 08:12

pokrovskyy