lib/hydra/worker.rb in hydra-0.19.0 vs lib/hydra/worker.rb in hydra-0.19.1
- old
+ new
@@ -7,28 +7,32 @@
# The general convention is to have one Worker per machine on a distributed
# network.
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
def initialize(opts = {})
@verbose = opts.fetch(:verbose) { false }
@io = opts.fetch(:io) { raise "No IO Object" }
@runners = []
@listeners = []
boot_runners(opts.fetch(:runners) { 1 })
+ @io.write(Hydra::Messages::Worker::WorkerBegin.new)
+
process_messages
-
+
@runners.each{|r| Process.wait r[:pid] }
end
# message handling methods
-
+
# When a runner wants a file, it hits this method with a message.
# Then the worker bubbles the file request up to the master.
def request_file(message, runner)
@io.write(RequestFile.new)
runner[:idle] = true
@@ -97,10 +101,10 @@
@listeners << Thread.new do
while @running
begin
message = @io.gets
if message and !message.class.to_s.index("Master").nil?
- trace "Received Message from Master"
+ trace "Received Message from Master"
trace "\t#{message.inspect}"
message.handle(self)
else
trace "Nothing from Master, Pinging"
@io.write Ping.new