lib/paraduct/runner.rb in paraduct-0.0.1.beta11 vs lib/paraduct/runner.rb in paraduct-0.0.1.beta12

- old
+ new

@@ -1,22 +1,21 @@ module Paraduct require "colorize" require "open3" class Runner - attr_reader :script, :params, :base_job_dir, :logger + attr_reader :script, :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] - @logger = Paraduct::ThreadLogger.new end def setup_dir FileUtils.mkdir_p(job_dir) unless job_dir.exist? Paraduct::SyncUtils.copy_recursive(Paraduct.config.root_dir, job_dir) @@ -50,10 +49,20 @@ def formatted_params @params.map{ |key, value| "#{key}=#{value}" }.join(", ") end + def logger + unless @logger + stdout_logger = Paraduct::ColoredLabelLogger.new(object_id) + file_logger = Logger.new(Pathname(@base_job_dir).join("#{job_name}.log")) + @logger = stdout_logger.extend(ActiveSupport::Logger.broadcast(file_logger)) + end + + @logger + end + def self.capitalize_keys(params) params.inject({}) do |res, (key, value)| res[key.upcase] = value res end @@ -63,10 +72,10 @@ def run_command(command) lines = "" IO.popen(command) do |io| while line = io.gets - @logger.info(line) + logger.info(line) lines << line end end status = $?