diff options
author | Eric Wong <e@80x24.org> | 2013-10-30 21:59:37 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-10-31 05:04:36 +0000 |
commit | 602432714cd436b6f255e6ba6bc6fffbf5eca051 (patch) | |
tree | 079520490f4c8cc89320658f2e83b597ec376091 /lib | |
parent | 5544418af3fb810ef90f33bcf88a434cd0349dc8 (diff) | |
download | yahns-602432714cd436b6f255e6ba6bc6fffbf5eca051.tar.gz |
It's usually given as a block, so Ruby won't care about arity there. Users will get the worker ID number as the first arg, making it possible to isolate some things to certain processes (e.g. for A/B testing).
Diffstat (limited to 'lib')
-rw-r--r-- | lib/yahns/config.rb | 7 | ||||
-rw-r--r-- | lib/yahns/server_mp.rb | 10 |
2 files changed, 8 insertions, 9 deletions
diff --git a/lib/yahns/config.rb b/lib/yahns/config.rb index 873722d..a46868b 100644 --- a/lib/yahns/config.rb +++ b/lib/yahns/config.rb @@ -103,13 +103,8 @@ class Yahns::Config # :nodoc: end def _add_hook(var, my_proc) - case my_proc - when Proc - my_proc.arity == 0 or raise ArgumentError, - "#{var}=#{my_proc.inspect} should not take arguments" - else + Proc === my_proc or raise ArgumentError, "invalid type: #{var}=#{my_proc.inspect}" - end # this sets: # :atfork_prepare, :atfork_parent, :atfork_child diff --git a/lib/yahns/server_mp.rb b/lib/yahns/server_mp.rb index 8272a9e..1e2f1c8 100644 --- a/lib/yahns/server_mp.rb +++ b/lib/yahns/server_mp.rb @@ -48,21 +48,25 @@ module Yahns::ServerMP # :nodoc: @sev = Yahns::Sigevent.new switch_user(*@user) if @user @user = @workers = nil - @atfork_child.each(&:call) if @atfork_child + __call_hooks(@atfork_child, worker.nr) @atfork_child = @atfork_parent = @atfork_prepare = nil end + def __call_hooks(ary, worker_nr) + ary.each { |x| x.call(worker_nr) } if ary + end + def spawn_missing_workers worker_nr = -1 until (worker_nr += 1) == @worker_processes @workers.value?(worker_nr) and next worker = Yahns::Worker.new(worker_nr) @logger.info("worker=#{worker_nr} spawning...") - @atfork_prepare.each(&:call) if @atfork_parent + __call_hooks(@atfork_prepare, worker_nr) if pid = fork @workers[pid] = worker.atfork_parent # XXX is this useful? - @atfork_parent.each(&:call) if @atfork_parent + __call_hooks(@atfork_parent, worker_nr) else worker_atfork_internal(worker) run_mp_worker(worker) |