lib/paraduct/parallel_runner.rb in paraduct-1.0.0.beta4 vs lib/paraduct/parallel_runner.rb in paraduct-1.0.0.beta5
- old
+ new
@@ -2,13 +2,14 @@
require "thread/pool"
class ParallelRunner
# run script with arguments
# @param script [String, Array<String>] script file, script(s)
+ # @param after_script [String, Array<String>] script file, script(s)
# @param product_variables [Array<Hash{String => String}>]
# @return [Paraduct::TestResponse]
- def self.perform_all(script, product_variables)
+ def self.perform_all(script: nil, after_script: nil, product_variables: nil)
test_response = Paraduct::TestResponse.new
base_job_dir = Paraduct.config.base_job_dir
FileUtils.mkdir_p(base_job_dir) unless base_job_dir.exist?
Paraduct.logger.info <<-EOS
@@ -18,30 +19,24 @@
pool = Thread.pool(Paraduct.config.max_threads)
begin
product_variables.each_with_index do |params, index|
runner = Paraduct::Runner.new(
- script: script,
params: params,
base_job_dir: base_job_dir,
job_id: index + 1,
)
pool.process do
runner.logger.info "[START] params: #{runner.formatted_params}"
runner.setup_dir if Paraduct.config.enable_rsync?
- begin
- stdout = runner.perform
- successful = true
- rescue Paraduct::Errors::ProcessError => e
- runner.logger.error "exitstatus=#{e.status}, #{e.inspect}"
- stdout = e.message
- successful = false
- rescue Exception => e
- runner.logger.error "Unknown error: #{e.inspect}"
- runner.logger.error e.backtrace.join("\n")
- successful = false
+ stdout, successful = perform_runner(runner, script)
+
+ unless after_script.blank?
+ after_stdout, after_successful = perform_runner(runner, after_script)
+ stdout << after_stdout
+ successful &&= after_successful
end
runner.logger.info "[END] params: #{runner.formatted_params}"
test_response.jobs_push(
@@ -58,8 +53,24 @@
end
raise Paraduct::Errors::DirtyExitError unless test_response.jobs_count == product_variables.count
test_response
+ end
+
+ private_class_method
+
+ def self.perform_runner(runner, script)
+ stdout = runner.perform(script)
+ [stdout, true]
+
+ rescue Paraduct::Errors::ProcessError => e
+ runner.logger.error "exitstatus=#{e.status}, #{e.inspect}"
+ [e.message, false]
+
+ rescue Exception => e
+ runner.logger.error "Unknown error: #{e.inspect}"
+ runner.logger.error e.backtrace.join("\n")
+ [nil, false]
end
end
end