lib/paraduct/runner.rb in paraduct-0.0.1.beta7 vs lib/paraduct/runner.rb in paraduct-0.0.1.beta8

- old
+ new

@@ -1,21 +1,21 @@ module Paraduct require "colorize" require "open3" class Runner - attr_reader :script, :params, :base_job_dir + attr_reader :script, :params, :base_job_dir, :logger # @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] - @color = Paraduct::Runner.next_color + @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) @@ -55,40 +55,16 @@ res[key.upcase] = value res end end - COLORS = [ - :cyan, - :yellow, - :green, - :magenta, - :red, - :blue, - :light, - :cyan, - :light_yellow, - :light_green, - :light_magenta, - :light_red, - :light_blue, - ] - def self.next_color - @@color_index ||= -1 - @@color_index = (@@color_index + 1) % COLORS.length - COLORS[@@color_index] - end - private def run_command(command) - thread_id = Thread.current.object_id.to_s - console_label = "[#{thread_id.colorize(@color)}]" - lines = "" IO.popen(command) do |io| while line = io.gets - Paraduct.logger.info "#{console_label} #{line.strip}" + @logger.info(line) lines << line end end status = $?