我在Heroku上使用Unicorn,我创建了一个EventMachine循环: (来自https://gist.github.com/jonkgrimes/5103321)
after_fork do |server,worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
if defined?(EventMachine)
unless EventMachine.reactor_running? && EventMachine.reactor_thread.alive?
if EventMachine.reactor_running?
EventMachine.stop_event_loop
EventMachine.release_machine
EventMachine.instance_variable_set("@reactor_running",false)
end
Thread.new { EventMachine.run }
end
end
Signal.trap("INT") { EventMachine.stop }
Signal.trap("TERM") { EventMachine.stop }
end
EventMachine运行良好,但在某些时候我的事件开始失败,因为“没有事件机器循环正在运行”。我想象两个可能的问题:
如何检测并重新启动崩溃的事件机器?和/或我该如何调试此问题?