gpt4 book ai didi

resque - 如何让 Bluepill 仅在达到安全状态后才重启 Resque worker

转载 作者:行者123 更新时间:2023-12-01 14:15:16 27 4
gpt4 key购买 nike

假设这是我的 worker :

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 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 等到它到达“安全” block 以重新启动或关闭。如何实现?

最佳答案

这样试试:

1) 使用 new_kill_child 设置 resque 以在 TERM/INT 上优雅地杀死 child 通过在启动时设置 TERM_CHILDRESQUE_TERM_TIMEOUT env 变量的方法:

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 向 child 发送 TERM 信号,等待 RESQUE_TERM_TIMEOUT,如果 child 仍在运行,则终止它。一定要

a) 将此超时设置得足够大,以便您的关键部分结束,

b) 在 process.stop_signals 中将 Bluepill TERM 超时配置为比 RESQUE_TERM_TIMEOUT 稍大一点,以便在等待子进程结束临界区时不杀死 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
end

关于resque - 如何让 Bluepill 仅在达到安全状态后才重启 Resque worker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18424290/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com