rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob 46571552d86d220189875616fd34107cc25c744a 636 bytes (raw)
$ git show v3.0.0:lib/rainbows/coolio/heartbeat.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
 
# -*- encoding: binary -*-
# :enddoc:
# This class handles the Unicorn fchmod heartbeat mechanism
# in Coolio-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 Rainbows::Coolio::Heartbeat < Coolio::TimerWatcher
  KATO = Rainbows::Coolio::KATO
  CONN = Rainbows::Coolio::CONN

  def on_timer
    if (ot = Rainbows.keepalive_timeout) >= 0
      ot = Time.now - ot
      KATO.delete_if { |client, time| time < ot and client.timeout? }
    end
    exit if (! Rainbows.tick && CONN.size <= 0)
  end
end

git clone https://yhbt.net/rainbows.git