lib/paraduct/parallel_runner.rb in paraduct-0.0.1.beta3 vs lib/paraduct/parallel_runner.rb in paraduct-0.0.1.beta4

- old
+ new

@@ -1,13 +1,14 @@ module Paraduct class ParallelRunner + # run script with arguments # @param script [String, Array<String>] script file, script(s) # @param product_variables [Array<Hash{String => String}>] - # @return [Array<String>] stdout messages of each job + # @return [Paraduct::TestResponse] def self.perform_all(script, product_variables) threads = [] - stdout_messages = [] + test_response = Paraduct::TestResponse.new base_job_dir = Paraduct.config.work_dir FileUtils.mkdir_p(base_job_dir) unless base_job_dir.exist? puts <<-EOS ====================================================== @@ -16,54 +17,44 @@ product_variables.each do |params| puts "params: #{params}" end product_variables.each do |params| - threads << Thread.new(base_job_dir, script, params) do |_base_job_dir, _script, _params| - job_dir = setup_runner(_base_job_dir, _params) - stdout = - begin - Paraduct::Runner.perform(_script, _params) - rescue Paraduct::ProcessError => e - e.message - end + runner = Paraduct::Runner.new( + script: script, + params: params, + base_job_dir: base_job_dir, + ) + threads << Thread.new(runner) do |_runner| + _runner.setup_dir + begin + stdout = _runner.perform + successful = true + rescue Paraduct::ProcessError => e + stdout = e.message + successful = false + end puts <<-EOS ====================================================== -params: #{_params} -job_dir: #{job_dir} +params: #{_runner.formatted_params} +job_name: #{_runner.job_name} +job_dir: #{_runner.job_dir} #{stdout} EOS - stdout_messages << stdout + test_response.jobs_push( + job_name: _runner.job_name, + params: _runner.params, + formatted_params: _runner.formatted_params, + successful: successful, + stdout: stdout, + ) end end threads.map(&:join) - stdout_messages + test_response end - - # @param source_dir [Pathname] - # @param destination_dir [Pathname] - def self.copy_recursive(source_dir, destination_dir) - FileUtils.mkdir_p(destination_dir) - source_dir.children.each do |source_child_dir| - begin - FileUtils.cp_r(source_child_dir, destination_dir) - rescue ArgumentError => e - # TODO: refactoring - raise unless e.message =~ /^cannot copy directory .+ to itself / - end - end - end - - def self.setup_runner(base_job_dir, params) - job_dir = Paraduct::Runner.parameterized_job_dir(base_job_dir, params) - FileUtils.mkdir_p(job_dir) unless job_dir.exist? - copy_recursive(Paraduct.config.root_dir, job_dir) - Dir.chdir(job_dir) - job_dir - end - private_class_method :setup_runner end end