Class: Polytrix::Executors::MixlibShellOutExecutor

Inherits:
Object
  • Object
show all
Includes:
DefaultLogger
Defined in:
lib/polytrix/executors/mixlib_shellout_executor.rb

Constant Summary collapse

MIXLIB_SHELLOUT_EXCEPTION_CLASSES =
Mixlib::ShellOut.constants.map do|name|
  klass = Mixlib::ShellOut.const_get(name)
  if klass.is_a?(Class) && klass <= RuntimeError
    klass
  else
    nil
  end
end.compact

Instance Method Summary collapse

Methods included from DefaultLogger

included

Methods included from DefaultLogger::ClassMethods

#logger

Instance Method Details

#execute(command, opts) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/polytrix/executors/mixlib_shellout_executor.rb', line 39

def execute(command, opts)
  prefix = opts.delete :prefix
  shell = Mixlib::ShellOut.new(command, opts)
  shell.live_stream = log_decorator $stdout, prefix
  shell.run_command
  execution_result = ExecutionResult.new exitstatus: shell.exitstatus, stdout: shell.stdout, stderr: shell.stderr
  # shell.error!
  execution_result
rescue SystemCallError, *MIXLIB_SHELLOUT_EXCEPTION_CLASSES, TypeError => e
  # See https://github.com/opscode/mixlib-shellout/issues/62
  execution_error = ExecutionError.new(e)
  execution_error.execution_result = execution_result
  raise execution_error
end

#log_decorator(_io, _prefix) ⇒ Object



35
36
37
# File 'lib/polytrix/executors/mixlib_shellout_executor.rb', line 35

def log_decorator(_io, _prefix)
  IOToLog.new(logger)
end