Class: Thrust::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/thrust/executor.rb

Constant Summary collapse

CommandFailed =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(out = STDERR, execution_helper = Thrust::ExecutionHelper.new) ⇒ Executor

Returns a new instance of Executor.



5
6
7
8
# File 'lib/thrust/executor.rb', line 5

def initialize(out = STDERR, execution_helper = Thrust::ExecutionHelper.new)
  @execution_helper = execution_helper
  @out = out
end

Instance Method Details

#capture_output_from_system(cmd, env = {}) ⇒ Object

Raises:



26
27
28
29
30
31
32
33
# File 'lib/thrust/executor.rb', line 26

def capture_output_from_system(cmd, env = {})
  @out.puts "Executing #{cmd}"
  execution = @execution_helper.capture_status_and_output_from_command(cmd, env)

  raise(CommandFailed, '******** Build failed ********') unless execution[:success]

  execution[:output]
end

#check_command_for_failure(cmd, env = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/thrust/executor.rb', line 35

def check_command_for_failure(cmd, env = {})
  @out.puts "Executing #{cmd} and checking for FAILURE"
  execution = @execution_helper.capture_status_and_output_from_command("#{cmd} 2>&1", env)
  result = execution[:output]

  @out.puts "Results:"
  @out.puts result

  Thrust::CedarResultsParser.parse_results_for_success(result)
end

#system(cmd, output_file = nil) ⇒ Object



19
20
21
22
23
24
# File 'lib/thrust/executor.rb', line 19

def system(cmd, output_file = nil)
  @out.puts "Executing #{cmd}"
  cmd += " > #{output_file}" if output_file

  @execution_helper.capture_status_from_command(cmd)
end

#system_or_exit(cmd, output_file = nil, env = {}) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/thrust/executor.rb', line 10

def system_or_exit(cmd, output_file = nil, env = {})
  @out.puts "Executing #{cmd}"
  cmd += " > #{output_file}" if output_file

  unless @execution_helper.capture_status_from_command(cmd, env)
    raise(CommandFailed, '******** Build failed ********')
  end
end