2013-01-15 195 views
15

重新啓動sidekiq的正確方法是什麼?當我啓動它時,似乎會緩存我的工作人員的代碼,所以每次我對工作人員進行更改時,都需要重新啓動它。我正在用Ctrl/C來做這件事,但這個過程需要很長時間才能讓我回到提示。重新啓動Sidekiq

有沒有辦法強制重啓立即生效?

我正在使用通過POW運行的Sinatra的最新版本。

回答

14

Sidekiq附帶命令sidekiqctl,該命令可以停止與您的Sidekiq進程關聯的PID。您傳遞PID文件和等待所有線程完成的秒數。

用法示例:

sidekiqctl stop #{rails_root}/tmp/pids/sidekiq_website_crawler.pid 60 

在這裏,60代表秒數等到所有Sidekiq線程處理完畢。如果60秒過去了,所有都沒有完成,它們會自動終止。

我也建議使用神寶石監控,停止,啓動並重新啓動Sidekiq。

一旦你這樣做了,你可以使用bundle exec god stop來停止所有的sidekiq線程。

這裏是我的上帝文件,作爲一個例子:

rails_env = ENV['RAILS_ENV'] || "development" 
rails_root = ENV['RAILS_ROOT'] || "/home/hwc218/BuzzSumo" 
God.watch do |w| 
    w.dir  = "#{rails_root}" 
    w.name  = "website_crawler" 
    w.interval = 30.seconds 
    w.env  = {"RAILS_ENV" => rails_env} 
    w.interval = 30.seconds 
    w.start = "bundle exec sidekiq -C#{rails_root}/config/sidekiq_website_crawler.yml" 
    w.stop = "sidekiqctl stop #{rails_root}/tmp/pids/sidekiq_website_crawler.pid 60" 
    w.keepalive 


    # determine the state on startup 
    w.transition(:init, { true => :up, false => :start }) do |on| 
    on.condition(:process_running) do |c| 
     c.running = true 
    end 
    end 

    # determine when process has finished starting 
     w.transition([:start, :restart], :up) do |on| 
     on.condition(:process_running) do |c| 
     c.running = true 
     c.interval = 5.seconds 
    end 

     # failsafe 
     on.condition(:tries) do |c| 
     c.times = 5 
     c.transition = :start 
     c.interval = 5.seconds 
    end 
    end 

    # start if process is not running 
    w.transition(:up, :start) do |on| 
    on.condition(:process_running) do |c| 
     c.running = false 
    end 
    end 

    w.restart_if do |restart| 
     restart.condition(:restart_file_touched) do |c| 
      c.interval = 5.seconds 
      c.restart_file = File.join(rails_root, 'tmp', 'restart.txt') 
     end 
    end 
end 
+0

完美。非常感謝。 – Undistraction

+0

我的sidekiq.pid文件應該是什麼樣子? – Undistraction

+2

它應該只包含Sidekiq進程ID的PID(編號)。運行ps -ef | grep「sidekiq」來獲取它。 –