lib/paraduct/runner.rb in paraduct-1.0.0.beta3 vs lib/paraduct/runner.rb in paraduct-1.0.0.beta4
- old
+ new
@@ -46,11 +46,11 @@
@params.map{ |key, value| "#{key}=#{value}" }.join(", ")
end
def logger
unless @logger
- stdout_logger = Paraduct::ColoredLabelLogger.new(object_id)
+ 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
@@ -58,22 +58,28 @@
private
def run_command(command)
full_stdout = ""
+ exit_status = nil
- PTY.spawn(command) do |stdin, _stdout, pid|
+ PTY.spawn(command) do |stdin, stdout, pid|
+ stdout.close_write
+ stdin.sync = true
+
begin
stdin.each do |line|
line.strip!
logger.info line
full_stdout << "#{line}\n"
end
rescue Errno::EIO
+ ensure
+ _, exit_status = Process.waitpid2(pid)
end
- exit_status = PTY.check(pid)
- raise Paraduct::Errors::ProcessError.new(full_stdout, exit_status) if exit_status && !exit_status.success?
end
+
+ raise Paraduct::Errors::ProcessError.new(full_stdout, exit_status) unless exit_status.success?
full_stdout
end
end
end