From 9916d7a6e5edad6d8f76de4c5abe251b9a03d628 Mon Sep 17 00:00:00 2001 From: Nick Gauthier Date: Wed, 27 Jan 2010 11:38:11 -0500 Subject: [PATCH] initial message passing structure for runner --- TODO | 54 +++++++++++++++++++++++ lib/hydra.rb | 3 ++ lib/hydra/message.rb | 8 ++++ lib/hydra/message/runner_requests_file.rb | 9 ++++ lib/hydra/runner.rb | 8 ++++ test/test_runner.rb | 20 +++++++++ 6 files changed, 102 insertions(+) create mode 100644 TODO create mode 100644 lib/hydra/message.rb create mode 100644 lib/hydra/message/runner_requests_file.rb create mode 100644 lib/hydra/runner.rb create mode 100644 test/test_runner.rb diff --git a/TODO b/TODO new file mode 100644 index 0000000..ff085c4 --- /dev/null +++ b/TODO @@ -0,0 +1,54 @@ +# runners = [] +# cores.each do |c| +# in = pipes[c][0] +# out = pipes[c][1] +# runners << TestRunner.new(in, out) +# end +# +# files = [ ... ] +# results = [] +# +# runners.each do |r| +# Thread.new do +# while !files.empty? +# results << r.run_file(files.pop) +# end +# r.shutdown +# end +# end +# +# puts results.join("\n") +# + + +# Master +# boot up workers +# listen for worker messages +# add worker messages to message queue +# process message queue +# "reply" to a message allows sending a message back down to worker +# +# When worker asks for file but no files left, send shutdown message to worker +# when worker connection breaks, end thread +# wait on all threads +# when all threads are done, all workers must be done +# +# +# Worker +# boot up runners +# listen for runner messages +# add runner messages to message queue +# process message queue +# "reply" to a message allows sending message back down to runner +# +# when a runner asks for file but master responds with shutdown, mark self +# as terminated, shut down runners. Any runner that asks for a file is +# auto-terminated +# wait for runner threads to finish +# then exit, breaking master connection +# +# Runner +# when booted, ask for a file +# then process messages on the queue +# when it's a file, run it and send a results message +# when it's a shutdown, break main loop diff --git a/lib/hydra.rb b/lib/hydra.rb index 633a0ac..b2c301d 100644 --- a/lib/hydra.rb +++ b/lib/hydra.rb @@ -1,2 +1,5 @@ require 'hydra/pipe' require 'hydra/ssh' +require 'hydra/message' +require 'hydra/runner' + diff --git a/lib/hydra/message.rb b/lib/hydra/message.rb new file mode 100644 index 0000000..d0f38ae --- /dev/null +++ b/lib/hydra/message.rb @@ -0,0 +1,8 @@ +module Hydra #:nodoc: + class Message #:nodoc: + def self.build(str) + eval(str).new + end + end +end +require 'hydra/message/runner_requests_file' diff --git a/lib/hydra/message/runner_requests_file.rb b/lib/hydra/message/runner_requests_file.rb new file mode 100644 index 0000000..e6100cb --- /dev/null +++ b/lib/hydra/message/runner_requests_file.rb @@ -0,0 +1,9 @@ +module Hydra #:nodoc: + module Messages #:nodoc: + class RunnerRequestsFile < Hydra::Message + def serialize + "Hydra::Messages::RunnerRequestsFile" + end + end + end +end diff --git a/lib/hydra/runner.rb b/lib/hydra/runner.rb new file mode 100644 index 0000000..c809162 --- /dev/null +++ b/lib/hydra/runner.rb @@ -0,0 +1,8 @@ +module Hydra #:nodoc: + class Runner + def initialize(io) + @io = io + @io.write Hydra::Messages::RunnerRequestsFile.new.serialize + end + end +end diff --git a/test/test_runner.rb b/test/test_runner.rb new file mode 100644 index 0000000..d89a41a --- /dev/null +++ b/test/test_runner.rb @@ -0,0 +1,20 @@ +require File.join(File.dirname(__FILE__), 'helper') + +class TestRunner < Test::Unit::TestCase + context "a test runner" do + setup do + @pipe = Hydra::Pipe.new + Process.fork do + @pipe.identify_as_child + Hydra::Runner.new(@pipe) + end + @pipe.identify_as_parent + end + should "request a file on boot" do + @message = Hydra::Message.build(@pipe.gets) + assert @message.is_a?(Hydra::Messages::RunnerRequestsFile) + end + should "return a result message after processing a file" + should "terminate when sent a shutdown message" + end +end