lib/pitchfork/children.rb in pitchfork-0.2.0 vs lib/pitchfork/children.rb in pitchfork-0.3.0

- old
+ new

@@ -27,33 +27,40 @@ end def register_mold(mold) @pending_molds[mold.pid] = mold @children[mold.pid] = mold - @mold = mold end def fetch(pid) @children.fetch(pid) end def update(message) - child = @children[message.pid] || (message.nr && @workers[message.nr]) - old_nr = child.nr + case message + when Message::MoldSpawned + mold = Worker.new(nil) + mold.update(message) + @pending_molds[mold.pid] = mold + @children[mold.pid] = mold + return mold + end + child = @children[message.pid] || (message.nr && @workers[message.nr]) child.update(message) if child.mold? - @workers.delete(old_nr) @pending_molds.delete(child.pid) @molds[child.pid] = child @mold = child end + if child.pid @children[child.pid] = child @pending_workers.delete(child.nr) end + child end def nr_alive?(nr) @workers.key?(nr) @@ -71,15 +78,18 @@ end child end def promote(worker) - @pending_molds[worker.pid] = worker worker.promote(self.last_generation += 1) end def pending_workers? !(@pending_workers.empty? && @pending_molds.empty?) + end + + def restarting_workers_count + @pending_workers.size + @workers.count { |_, w| w.exiting? } end def pending_promotion? !@pending_molds.empty? end