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:
Lee Bankewitz and Luke Melia 2010-06-08 11:02:57 -04:00
parent e5633f42ac
commit c8091718eb
4 changed files with 45 additions and 18 deletions

View File

@ -10,14 +10,23 @@ module Hydra #:nodoc:
def initialize(output = $stdout)
@output = output
end
# Fired when testing has started
def testing_begin(files)
end
# Fired when testing finishes
# Fired when testing finishes, after the workers shutdown
def testing_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
def file_begin(file)
end

View File

@ -93,6 +93,9 @@ module Hydra #:nodoc:
end
# Message handling
def worker_begin(worker)
@event_listeners.each {|l| l.worker_begin(worker) }
end
# Send a file down to a worker.
def send_file(worker)
@ -120,6 +123,10 @@ module Hydra #:nodoc:
trace "#{@incomplete_files.size} Files Remaining"
@event_listeners.each{|l| l.file_end(message.file, message.output) }
if @incomplete_files.empty?
@workers.each do |worker|
@event_listeners.each{|l| l.worker_end(worker) }
end
shutdown_all_workers
else
send_file(worker)
@ -156,6 +163,7 @@ module Hydra #:nodoc:
pipe.identify_as_child
Hydra::Worker.new(:io => pipe, :runners => runners, :verbose => @verbose)
end
pipe.identify_as_parent
@workers << { :pid => child, :io => pipe, :idle => false, :type => :local }
end

View File

@ -8,6 +8,12 @@ module Hydra #:nodoc:
end
end
class WorkerBegin < Hydra::Message
def handle(master, worker)
master.worker_begin(worker)
end
end
# Message telling the Runner to run a file
class RunFile < Hydra::Message
# The file that should be run

View File

@ -9,6 +9,8 @@ module Hydra #:nodoc:
class Worker
include Hydra::Messages::Worker
traceable('WORKER')
attr_reader :runners
# Create a new worker.
# * io: The IO object to use to communicate with the master
# * num_runners: The number of runners to launch
@ -19,6 +21,8 @@ module Hydra #:nodoc:
@listeners = []
boot_runners(opts.fetch(:runners) { 1 })
@io.write(Hydra::Messages::Worker::WorkerBegin.new)
process_messages
@runners.each{|r| Process.wait r[:pid] }