Question: Start Sidekiq automatically if it is not in running state - Rails


Start Sidekiq automatically if it is not in running state - Rails

Answers 3
Added at 2016-12-28 11:12

I'm using redis server and sidekiq for my cron jobs but some time sidekiq kills automatically at backend.

I want to restart sidekiq from my controller's action or automatically when it kills down without stoping my rails application server.

Please suggest me how can I manage this problem?

nr: #1 dodano: 2016-12-28 11:12

It shouldn't be your applications responsibility to start external programs.

Install and use a server monitoring tool like bluepill or god to ensure all dependencies are up and running.

nr: #2 dodano: 2016-12-28 11:12

You can check sidekiq and redis server running or not running by :

  def redis_connected?
    !!Sidekiq.redis(&:info) rescue false

  def sidekiq_connected?
    ps =
    ps.size > 0 ? true : false 

and you can also start from your controller but this is not a good way because it will start sidekiq but kill rails server.

  def start_sidekiq
    system "redis-server &" if !redis_connected?
    system "bundle exec sidekiq -d" if !sidekiq_connected?
    flash[:sidekiq_notification]="Starting server... Please refresh after few seconds"
    redirect_to :back

or install and use a server monitoring tool

nr: #3 dodano: 2016-12-28 11:12

I believe, that this is a wrong way to do it.

I suggest you to setup a monitorring system, which will automatically start your failing workers - you can use God, Monit or whatever you like.

However, if you realy need it, you can perform system calls from ruby - just wrap it in `` or %x{} (for example %x{ bundle exec sidekiq })

Source Show
◀ Wstecz