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.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lib/rainbows.rb') diff --git a/lib/rainbows.rb b/lib/rainbows.rb index a8985c6..5bd8693 100644 --- a/lib/rainbows.rb +++ b/lib/rainbows.rb @@ -5,9 +5,20 @@ module Rainbows # global vars because class/instance variables are confusing me :< # this struct is only accessed inside workers and thus private to each - G = Struct.new(:cur, :max, :logger, :alive, :app).new # G.cur may not be used the network concurrency model - G.alive = true + class State < Struct.new(:alive,:m,:cur,:server,:tmp) + def tick + tmp.chmod(self.m = m == 0 ? 1 : 0) + alive && server.master_pid == Process.ppid or quit! + end + + def quit! + self.alive = false + server.class.const_get(:LISTENERS).map! { |s| s.close rescue nil } + false + end + end + G = State.new(true, 0, 0) require 'rainbows/const' require 'rainbows/http_server' -- cgit v1.2.3-24-ge0c7