Class: PeerCommander::CommandRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/peer_commander/command_runner.rb

Overview

Runs the listed commands with a configurable level of parallelism

Instance Method Summary collapse

Constructor Details

#initialize(commands) ⇒ CommandRunner

Returns a new instance of CommandRunner.



7
8
9
10
# File 'lib/peer_commander/command_runner.rb', line 7

def initialize(commands)
  @commands = commands
  @command_results = []
end

Instance Method Details

#all_commandsObject



29
30
31
32
33
# File 'lib/peer_commander/command_runner.rb', line 29

def all_commands
  raise Errors::CommandNotExecutedError if command_results.empty?

  @command_results
end

#durationObject



47
48
49
50
51
# File 'lib/peer_commander/command_runner.rb', line 47

def duration
  raise Errors::CommandNotExecutedError if command_results.empty?

  @duration
end

#execute(parallelism: 1) ⇒ Object



12
13
14
15
16
17
# File 'lib/peer_commander/command_runner.rb', line 12

def execute(parallelism: 1)
  start = Time.now
  @command_results = ParallelExecutor.new.execute(commands, parallelism)
  @duration = Time.now - start
  @command_results
end

#failed?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/peer_commander/command_runner.rb', line 25

def failed?
  !success?
end

#failed_commandsObject



41
42
43
44
45
# File 'lib/peer_commander/command_runner.rb', line 41

def failed_commands
  raise Errors::CommandNotExecutedError if command_results.empty?

  @command_results.select(&:failed?)
end

#success?Boolean

Returns:

  • (Boolean)

Raises:



19
20
21
22
23
# File 'lib/peer_commander/command_runner.rb', line 19

def success?
  raise Errors::CommandNotExecutedError if command_results.empty?

  @command_results.all?(&:success?)
end

#successful_commandsObject



35
36
37
38
39
# File 'lib/peer_commander/command_runner.rb', line 35

def successful_commands
  raise Errors::CommandNotExecutedError if command_results.empty?

  @command_results.select(&:success?)
end