introduce custom listeners for worker_begin/worker_end
Conflicts: lib/hydra/listener/abstract.rb lib/hydra/message/worker_messages.rb
This commit is contained in:
parent
e5633f42ac
commit
c8091718eb
@ -10,14 +10,23 @@ module Hydra #:nodoc:
|
|||||||
def initialize(output = $stdout)
|
def initialize(output = $stdout)
|
||||||
@output = output
|
@output = output
|
||||||
end
|
end
|
||||||
|
|
||||||
# Fired when testing has started
|
# Fired when testing has started
|
||||||
def testing_begin(files)
|
def testing_begin(files)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Fired when testing finishes
|
# Fired when testing finishes, after the workers shutdown
|
||||||
def testing_end
|
def testing_end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Fired after runner processes have been started
|
||||||
|
def worker_begin(worker)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Fired before shutting down the worker
|
||||||
|
def worker_end(worker)
|
||||||
|
end
|
||||||
|
|
||||||
# Fired when a file is started
|
# Fired when a file is started
|
||||||
def file_begin(file)
|
def file_begin(file)
|
||||||
end
|
end
|
||||||
|
@ -93,6 +93,9 @@ module Hydra #:nodoc:
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Message handling
|
# Message handling
|
||||||
|
def worker_begin(worker)
|
||||||
|
@event_listeners.each {|l| l.worker_begin(worker) }
|
||||||
|
end
|
||||||
|
|
||||||
# Send a file down to a worker.
|
# Send a file down to a worker.
|
||||||
def send_file(worker)
|
def send_file(worker)
|
||||||
@ -120,6 +123,10 @@ module Hydra #:nodoc:
|
|||||||
trace "#{@incomplete_files.size} Files Remaining"
|
trace "#{@incomplete_files.size} Files Remaining"
|
||||||
@event_listeners.each{|l| l.file_end(message.file, message.output) }
|
@event_listeners.each{|l| l.file_end(message.file, message.output) }
|
||||||
if @incomplete_files.empty?
|
if @incomplete_files.empty?
|
||||||
|
@workers.each do |worker|
|
||||||
|
@event_listeners.each{|l| l.worker_end(worker) }
|
||||||
|
end
|
||||||
|
|
||||||
shutdown_all_workers
|
shutdown_all_workers
|
||||||
else
|
else
|
||||||
send_file(worker)
|
send_file(worker)
|
||||||
@ -156,6 +163,7 @@ module Hydra #:nodoc:
|
|||||||
pipe.identify_as_child
|
pipe.identify_as_child
|
||||||
Hydra::Worker.new(:io => pipe, :runners => runners, :verbose => @verbose)
|
Hydra::Worker.new(:io => pipe, :runners => runners, :verbose => @verbose)
|
||||||
end
|
end
|
||||||
|
|
||||||
pipe.identify_as_parent
|
pipe.identify_as_parent
|
||||||
@workers << { :pid => child, :io => pipe, :idle => false, :type => :local }
|
@workers << { :pid => child, :io => pipe, :idle => false, :type => :local }
|
||||||
end
|
end
|
||||||
|
@ -8,6 +8,12 @@ module Hydra #:nodoc:
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class WorkerBegin < Hydra::Message
|
||||||
|
def handle(master, worker)
|
||||||
|
master.worker_begin(worker)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Message telling the Runner to run a file
|
# Message telling the Runner to run a file
|
||||||
class RunFile < Hydra::Message
|
class RunFile < Hydra::Message
|
||||||
# The file that should be run
|
# The file that should be run
|
||||||
|
@ -9,6 +9,8 @@ module Hydra #:nodoc:
|
|||||||
class Worker
|
class Worker
|
||||||
include Hydra::Messages::Worker
|
include Hydra::Messages::Worker
|
||||||
traceable('WORKER')
|
traceable('WORKER')
|
||||||
|
|
||||||
|
attr_reader :runners
|
||||||
# Create a new worker.
|
# Create a new worker.
|
||||||
# * io: The IO object to use to communicate with the master
|
# * io: The IO object to use to communicate with the master
|
||||||
# * num_runners: The number of runners to launch
|
# * num_runners: The number of runners to launch
|
||||||
@ -19,6 +21,8 @@ module Hydra #:nodoc:
|
|||||||
@listeners = []
|
@listeners = []
|
||||||
|
|
||||||
boot_runners(opts.fetch(:runners) { 1 })
|
boot_runners(opts.fetch(:runners) { 1 })
|
||||||
|
@io.write(Hydra::Messages::Worker::WorkerBegin.new)
|
||||||
|
|
||||||
process_messages
|
process_messages
|
||||||
|
|
||||||
@runners.each{|r| Process.wait r[:pid] }
|
@runners.each{|r| Process.wait r[:pid] }
|
||||||
|
Loading…
Reference in New Issue
Block a user