Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 542
Jai Kumar Rajput Avatar asked Dec 28 '16 10:12

Jai Kumar Rajput


1 Answers

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

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

  def sidekiq_connected?
    ps = Sidekiq::ProcessSet.new
    ps.size > 0 ? true : false 
  end

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
  end

or install and use a server monitoring tool

like image 83
Nitisha Avatar answered Oct 21 '22 02:10

Nitisha