假设这是我的工人:
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 Scheduler查询,这是我的Bluepill配置文件:
...
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等待,直到它到达“安全”块才能重新启动或关闭。如何做到这一点?
发布于 2013-09-22 19:13:12
这样试试:
1)通过在启动时设置TERM_CHILD和RESQUE_TERM_TIMEOUT环境变量,将resque设置为在TERM/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,如果子进程仍在运行,则终止它。一定要
a)将此超时设置得足够大,以使您的临界区结束,
b)将process.stop_signals中的Bluepill TERM timeout配置为比RESQUE_TERM_TIMEOUT稍大一点,以便在worker等待子进程结束临界区时不杀死worker。
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
endhttps://stackoverflow.com/questions/18424290
复制相似问题