class Sponges::Worker
This class helps building new workers.
Attributes
name[R]
supervisor[R]
Public Class Methods
new(supervisor, name)
click to toggle source
Initialize an Worker
with a supervisor and its future name
@param [Sponges::Supervisor] supervisor @param [String] name
@return [undefined]
# File lib/sponges/worker.rb, line 17 def initialize(supervisor, name) @supervisor, @name = supervisor, name end
Public Instance Methods
call()
click to toggle source
Forks a brandly new worker.
@return [Integer] Pid of the new worker
# File lib/sponges/worker.rb, line 25 def call fork do $PROGRAM_NAME = name (Sponges::STOP_SIGNALS + [:HUP]).each { |sig| trap(sig) { exit!(0) } } trap_supervisor_sigkill! Sponges::Hook.after_fork supervisor.call end end
Private Instance Methods
trap_supervisor_sigkill!()
click to toggle source
# File lib/sponges/worker.rb, line 37 def trap_supervisor_sigkill! Thread.new do while alive?(supervisor.pid) do sleep Configuration.polling end exit end end