simplify keepalive_timeout accounting
[rainbows.git] / lib / rainbows / coolio / heartbeat.rb
blob4506b8475d21f1414cba26a04db4b6291b71e8f9
1 # -*- encoding: binary -*-
2 # :enddoc:
3 # This class handles the Unicorn fchmod heartbeat mechanism
4 # in Coolio-based concurrency models to prevent the master
5 # process from killing us unless we're blocked.  This class
6 # will also detect and execute the graceful exit if triggered
7 # by SIGQUIT
8 class Rainbows::Coolio::Heartbeat < Coolio::TimerWatcher
9   KATO = Rainbows::Coolio::KATO
10   CONN = Rainbows::Coolio::CONN
11   G = Rainbows::G
13   def on_timer
14     if (ot = Rainbows.keepalive_timeout) >= 0
15       ot = Time.now - ot
16       KATO.delete_if { |client, time| time < ot and client.timeout? }
17     end
18     exit if (! G.tick && CONN.size <= 0)
19   end
20 end