bump to unicorn 5.0.1, use monotonic clock
[rainbows.git] / lib / rainbows / coolio / heartbeat.rb
blobfcfbb0fd91325077b0502b6f17aa9eba64bb17ee
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   Rainbows.config!(self, :keepalive_timeout)
12   Rainbows.at_quit { KATO.each_key { |client| client.timeout? }.clear }
14   def on_timer
15     if (ot = KEEPALIVE_TIMEOUT) >= 0
16       ot = Rainbows.now - ot
17       KATO.delete_if { |client, time| time < ot and client.timeout? }
18     end
19     exit if (! Rainbows.tick && CONN.size <= 0)
20   end
21 end