Class: Paraduct::Runner
- Inherits:
-
Object
- Object
- Paraduct::Runner
- Defined in:
- lib/paraduct/runner.rb
Instance Attribute Summary collapse
-
#base_job_dir ⇒ Object
readonly
Returns the value of attribute base_job_dir.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #formatted_params ⇒ Object
-
#initialize(params: nil, base_job_dir: nil, job_id: nil) ⇒ Runner
constructor
A new instance of Runner.
- #job_dir ⇒ Object
- #job_name ⇒ Object
- #logger ⇒ Object
-
#perform(script) ⇒ String
run script with params.
- #setup_dir ⇒ Object
Constructor Details
#initialize(params: nil, base_job_dir: nil, job_id: nil) ⇒ Runner
Returns a new instance of Runner.
10 11 12 13 14 |
# File 'lib/paraduct/runner.rb', line 10 def initialize(params: nil, base_job_dir: nil, job_id: nil) @params = params @base_job_dir = base_job_dir @job_id = job_id end |
Instance Attribute Details
#base_job_dir ⇒ Object (readonly)
Returns the value of attribute base_job_dir.
5 6 7 |
# File 'lib/paraduct/runner.rb', line 5 def base_job_dir @base_job_dir end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'lib/paraduct/runner.rb', line 5 def params @params end |
Instance Method Details
#formatted_params ⇒ Object
44 45 46 |
# File 'lib/paraduct/runner.rb', line 44 def formatted_params @params.map { |key, value| "#{key}=#{value}" }.join(", ") end |
#job_dir ⇒ Object
36 37 38 |
# File 'lib/paraduct/runner.rb', line 36 def job_dir Pathname(@base_job_dir).join(job_name) end |
#job_name ⇒ Object
40 41 42 |
# File 'lib/paraduct/runner.rb', line 40 def job_name @params.map { |key, value| "#{key}_#{value}" }.join("_").gsub(%r{[/ ]}, "_") end |
#logger ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/paraduct/runner.rb', line 48 def logger unless @logger stdout_logger = Paraduct::ColoredLabelLogger.new(formatted_params) file_logger = Logger.new(Pathname(@base_job_dir).join("#{job_name}.log")) @logger = stdout_logger.extend(ActiveSupport::Logger.broadcast(file_logger)) end @logger end |
#perform(script) ⇒ String
run script with params
26 27 28 29 30 31 32 33 34 |
# File 'lib/paraduct/runner.rb', line 26 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| stdout << run_command("#{variable_string} #{command}") stdout end end |
#setup_dir ⇒ Object
16 17 18 19 20 |
# File 'lib/paraduct/runner.rb', line 16 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 |