Class: Messagebus::Swarm::Controller::ProcessManagementConcerns::DroneForker

Inherits:
Object
  • Object
show all
Defined in:
lib/messagebus/swarm/controller.rb

Instance Method Summary collapse

Constructor Details

#initialize(drones) ⇒ DroneForker

Returns a new instance of DroneForker.



138
139
140
# File 'lib/messagebus/swarm/controller.rb', line 138

def initialize(drones)
  @drones = drones
end

Instance Method Details

#startObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/messagebus/swarm/controller.rb', line 142

def start
  # Intentionally not doing this with a map so if we get a signal
  # while building this list up, we'll still have some/most of the
  # pids. This still isn't perfect. Sure there's a perfect way to
  # do this.
  @pids = []
  parent_pid = Process.pid

  @drones.map do |drone|
    @pids << fork do
      $0 = "ruby messagebus_swarm worker for #{parent_pid}-#{drone.id}"
      Messagebus::Swarm::Controller.after_fork_procs.each{|after_fork_proc| after_fork_proc.call }
      register_stop_signal_handler(drone)
      drone.processing_loop
    end
  end
end

#stopObject



164
165
166
167
168
# File 'lib/messagebus/swarm/controller.rb', line 164

def stop
  @pids.each do |pid|
    Process.kill(STOP_SUBPROCESS_SIGNAL, pid)
  end
end

#waitObject



160
161
162
# File 'lib/messagebus/swarm/controller.rb', line 160

def wait
  Process.wait
end