From 1a9a718a3f9a5b582a4a339a9bb9249c2ca392d7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 6 Nov 2009 19:45:17 -0800 Subject: cleanup worker heartbeat and master deathwatch It turns out neither the EventMachine and Rev classes checked for master death in its heartbeat mechanism. Since we managed to forget the same thing twice, we now have a test case for it and also centralized the code to remove duplication. --- lib/rainbows/base.rb | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'lib/rainbows/base.rb') diff --git a/lib/rainbows/base.rb b/lib/rainbows/base.rb index 9da148c..9b50d9a 100644 --- a/lib/rainbows/base.rb +++ b/lib/rainbows/base.rb @@ -26,20 +26,14 @@ module Rainbows def init_worker_process(worker) super(worker) - G.cur = 0 - G.max = worker_connections - G.logger = logger - G.app = app + G.server = self + G.tmp = worker.tmp # we're don't use the self-pipe mechanism in the Rainbows! worker # since we don't defer reopening logs HttpServer::SELF_PIPE.each { |x| x.close }.clear trap(:USR1) { reopen_worker_logs(worker.nr) rescue nil } - trap(:QUIT) do - G.alive = false - # closing anything we IO.select on will raise EBADF - HttpServer::LISTENERS.map! { |s| s.close rescue nil } - end + trap(:QUIT) { G.quit! } [:TERM, :INT].each { |sig| trap(sig) { exit!(0) } } # instant shutdown logger.info "Rainbows! #@use worker_connections=#@worker_connections" end @@ -89,13 +83,12 @@ module Rainbows logger.error e.backtrace.join("\n") end - def join_threads(threads, worker) - Rainbows::G.alive = false + def join_threads(threads) + G.quit! expire = Time.now + (timeout * 2.0) - m = 0 until (threads.delete_if { |thr| ! thr.alive? }).empty? threads.each { |thr| - worker.tmp.chmod(m = 0 == m ? 1 : 0) + G.tick thr.join(1) break if Time.now >= expire } -- cgit v1.2.3-24-ge0c7