lib/paraduct/runner.rb in paraduct-1.0.0.beta4 vs lib/paraduct/runner.rb in paraduct-1.0.0.beta5
- old
+ new
@@ -1,35 +1,34 @@
module Paraduct
require "pty"
class Runner
- attr_reader :script, :params, :base_job_dir
+ attr_reader :params, :base_job_dir
- # @param args
- # @option args :script [String, Array<String>] script file, script(s)
- # @option args :params [Hash{String => String}] key is capitalized and value is quoted (ex. foo=1 => FOO="1" )
- # @option args :base_job_dir [String]
- def initialize(args={})
- @script = args[:script]
- @params = args[:params]
- @base_job_dir = args[:base_job_dir]
- @job_id = args[:job_id]
+ # @param params [Hash{String => String}] value is quoted (ex. FOO=1 => FOO="1" )
+ # @param base_job_dir [String]
+ # @param job_id [String]
+ def initialize(params: nil, base_job_dir: nil, job_id: nil)
+ @params = params
+ @base_job_dir = base_job_dir
+ @job_id = job_id
end
def setup_dir
FileUtils.mkdir_p(job_dir) unless job_dir.exist?
Paraduct::SyncUtils.copy_recursive(Paraduct.config.root_dir, job_dir)
Dir.chdir(job_dir)
end
# run script with params
+ # @param script [String, Array<String>] script file, script(s)
# @return [String] stdout
# @raise [Paraduct::Errors::ProcessError] command exited error status
- def perform
+ def perform(script)
export_variables = @params.reverse_merge("PARADUCT_JOB_ID" => @job_id, "PARADUCT_JOB_NAME" => job_name)
variable_string = export_variables.map{ |key, value| %(export #{key}="#{value}";) }.join(" ")
- Array.wrap(@script).inject("") do |stdout, command|
+ Array.wrap(script).inject("") do |stdout, command|
stdout << run_command("#{variable_string} #{command}")
stdout
end
end