如何使Bluepill仅在达到安全状态后重新启动Resque工人
假设这是我的工人:如何使Bluepill仅在达到安全状态后重新启动Resque工人,resque,bluepill,Resque,Bluepill,假设这是我的工人: 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调度程序进行协商,这是我的Blu
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配置:
...
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等到它到达“安全”块后重新启动或关闭。如何做到这一点?请尝试以下方法:
1) 通过在开始时设置TERM\u CHILD
和resque\u TERM\u TIMEOUT
env变量,设置resque以优雅地杀死TERM/INT上的子项:
process.start_command = "rake environment resque:work QUEUE=foo RAILS_ENV=production TERM_CHILD=1 RESQUE_TERM_TIMEOUT=20.0"
RESQUE\u TERM\u TIMEOUT
的默认值为
这将使resque向子级发送TERM信号,等待resque\u TERM\u超时
,如果子级仍在运行,则将其杀死。一定要
a) 将此超时设置为足够大,以便关键部分结束
b) 在进程中配置Bluepill TERM timeout。停止\u信号
稍微大于重新设置\u TERM \u timeout
以在等待子进程结束关键部分时不杀死工作进程
2) 处理子进程中的术语信号,使其优雅地停止:
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
class-FooWorker
类是否可以将长操作放入数据库事务中,以便在终止时使系统保持干净状态?这不是你想要的答案,但也许这是另一种方法?你找到解决办法了吗?