From b96822f15c9ede2a0053afeb1a5f43d3df7d7d3d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 30 Oct 2009 18:14:37 -0700 Subject: rev: split out heartbeat class This module will be reused in upcoming Rev-derived concurrency models. --- lib/rainbows/rev.rb | 19 +------------------ lib/rainbows/rev/heartbeat.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 18 deletions(-) create mode 100644 lib/rainbows/rev/heartbeat.rb (limited to 'lib') diff --git a/lib/rainbows/rev.rb b/lib/rainbows/rev.rb index d2bbc49..a1a4e6a 100644 --- a/lib/rainbows/rev.rb +++ b/lib/rainbows/rev.rb @@ -1,6 +1,5 @@ # -*- encoding: binary -*- -require 'rev' -Rev::VERSION >= '0.3.0' or abort 'rev >= 0.3.0 is required' +require 'rainbows/rev/heartbeat' require 'rainbows/ev_core' module Rainbows @@ -168,22 +167,6 @@ module Rainbows end end - # This timer handles the fchmod heartbeat to prevent our master - # from killing us. - class Heartbeat < ::Rev::TimerWatcher - G = Rainbows::G - - def initialize(tmp) - @m, @tmp = 0, tmp - super(1, true) - end - - def on_timer - @tmp.chmod(@m = 0 == @m ? 1 : 0) - exit if (! G.alive && G.cur <= 0) - end - end - # runs inside each forked worker, this sits around and waits # for connections and doesn't die until the parent dies (or is # given a INT, QUIT, or TERM signal) diff --git a/lib/rainbows/rev/heartbeat.rb b/lib/rainbows/rev/heartbeat.rb new file mode 100644 index 0000000..755b136 --- /dev/null +++ b/lib/rainbows/rev/heartbeat.rb @@ -0,0 +1,27 @@ +# -*- encoding: binary -*- +require 'rev' +Rev::VERSION >= '0.3.0' or abort 'rev >= 0.3.0 is required' + +module Rainbows + module Rev + + # This class handles the Unicorn fchmod heartbeat mechanism + # in Rev-based concurrency models to prevent the master + # process from killing us unless we're blocked. This class + # will also detect and execute the graceful exit if triggered + # by SIGQUIT + class Heartbeat < ::Rev::TimerWatcher + # +tmp+ must be a +File+ that responds to +chmod+ + def initialize(tmp) + @m, @tmp = 0, tmp + super(1, true) + end + + def on_timer + @tmp.chmod(@m = 0 == @m ? 1 : 0) + exit if (! G.alive && G.cur <= 0) + end + + end + end +end -- cgit v1.2.3-24-ge0c7