Class: UnicornHorn::Runner

Inherits:
SelfPipeDaemon show all
Defined in:
lib/unicorn_horn/runner.rb

Constant Summary

Constants inherited from SelfPipeDaemon

SelfPipeDaemon::SELF_PIPE, SelfPipeDaemon::SIG_QUEUE

Instance Method Summary collapse

Methods inherited from SelfPipeDaemon

#forget, #ploop, #psleep, #pwake, #register

Constructor Details

#initialize(handlers) ⇒ Runner

Returns a new instance of Runner.



4
5
6
7
# File 'lib/unicorn_horn/runner.rb', line 4

def initialize handlers
  super()
  @workers = handlers.map{ |handler| Worker.new handler }
end

Instance Method Details

#startObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/unicorn_horn/runner.rb', line 9

def start
  register :QUIT, :INT, :TERM, :CHLD, :HUP
  AFTER_FORK << proc{ @workers.clear; forget }
  @workers.each(&:launch!)

  ploop do |signal|
    reap
    case signal
    when nil
      @workers.each(&:kill_if_idle)
      @workers.each{ |w| w.wpid or w.launch! }
      psleep 1
    when :CHLD;       next
    when :HUP;        raze(:QUIT,  5);
    when :QUIT;       raze(:QUIT, 60); break
    when :TERM, :INT; raze(:TERM,  5); break
    end
  end
end