Class: Sponges::Worker

Inherits:
Object
  • Object
show all
Includes:
Alive
Defined in:
lib/sponges/worker.rb

Overview

This class helps building new workers.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(supervisor, name) ⇒ undefined

Initialize an Worker with a supervisor and its future name

Parameters:



17
18
19
# File 'lib/sponges/worker.rb', line 17

def initialize(supervisor, name)
  @supervisor, @name = supervisor, name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/sponges/worker.rb', line 7

def name
  @name
end

#supervisorObject (readonly)

Returns the value of attribute supervisor.



7
8
9
# File 'lib/sponges/worker.rb', line 7

def supervisor
  @supervisor
end

Instance Method Details

#callInteger

Forks a brandly new worker.

Returns:

  • (Integer)

    Pid of the 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