Class: Sponges::Worker
Overview
This class helps building new workers.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#supervisor ⇒ Object
readonly
Returns the value of attribute supervisor.
Instance Method Summary collapse
-
#call ⇒ Integer
Forks a brandly new worker.
-
#initialize(supervisor, name) ⇒ undefined
constructor
Initialize an Worker with a supervisor and its future name.
Constructor Details
#initialize(supervisor, name) ⇒ undefined
Initialize an Worker with a supervisor and its future name
17 18 19 |
# File 'lib/sponges/worker.rb', line 17 def initialize(supervisor, name) @supervisor, @name = supervisor, name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/sponges/worker.rb', line 7 def name @name end |
#supervisor ⇒ Object (readonly)
Returns the value of attribute supervisor.
7 8 9 |
# File 'lib/sponges/worker.rb', line 7 def supervisor @supervisor end |
Instance Method Details
#call ⇒ Integer
Forks a brandly new worker.
25 26 27 28 29 30 31 32 33 |
# 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 |