2013-08-24 50 views
3

比方說,這是我的工作人員:如何使Bluepill重啓Resque工人只能達到安全狀態後

class FooWorker 
    @queue = :foo 

    def self.perform 
    User.all.each do |u| 
     ... 
     Do Long Operations (Unsafe to kill) 
     ... 

     # Here it's safe to break the worker and restart 
    end 
    end 
end 

我與Resque調度入隊這一點,這是我的Bluepill的conf:

... 
app.process(process_name) do |process| 
    process.group   = "resque" 
    process.start_command = "rake environment resque:work QUEUE=foo RAILS_ENV=production" 
    ... 
    process.stop_signals = [:quit, 5.seconds, :term, 1.minute, :kill] 
    process.daemonize  = true 

    process.start_grace_time = 30.seconds 
    process.stop_grace_time = 80.seconds 

    process.monitor_children do |child_process| 
    child_process.stop_command = "kill -QUIT {{PID}}" 

    child_process.checks :mem_usage, :every => 30.seconds, :below => 500.megabytes, :times => [3,4], :fires => :stop 
    end 
end 
.... 

我想使Bluepill或Resque等到它到達「安全」區塊才能重新啓動或關閉。如何實現這一目標?

+0

是你的長期操作的東西,可以被放入一個數據庫事務,因此,如果殺了他們讓系統處於清潔狀態?不是你正在尋找的答案,但也許這是一種替代方法? –

+0

您是否找到解決方案? – Robert

回答

0

試試這樣說:

1)設置resque通過在開始設置TERM_CHILDRESQUE_TERM_TIMEOUT ENV變量殺死正常的短期/ INT與new_kill_child法兒:

process.start_command = "rake environment resque:work QUEUE=foo RAILS_ENV=production TERM_CHILD=1 RESQUE_TERM_TIMEOUT=20.0" 

RESQUE_TERM_TIMEOUT默認值爲4 seconds

這將使resque發送TERM信號給孩子,等待RESQUE_TERM_TIMEOUT,如果孩子仍在運行,殺死它。一定要

一)設置的超時足夠大,你的關鍵節結束,

二)process.stop_signals配置Bluepill TERM超時是有點比RESQUE_TERM_TIMEOUT大不殺工人在等待子進程結束關鍵部分。

2)子進程句柄TERM信號停止正常:

class FooWorker 
    class << self 
    attr_accessor :stop 
    end 

    @queue = :foo 
    def self.perform 
    User.all.each do |u| 
     ... 
     Do Long Operations (Unsafe to kill) 
     ... 

     # Here it's safe to break the worker and restart 
     return if FooWorker.stop 
    end 
    end 
end 

trap('TERM') do 
    FooWorker.stop = true 
end