Class: PeerCommander::CommandRunner
- Inherits:
-
Object
- Object
- PeerCommander::CommandRunner
- Defined in:
- lib/peer_commander/command_runner.rb
Overview
Runs the listed commands with a configurable level of parallelism
Instance Method Summary collapse
- #all_commands ⇒ Object
- #duration ⇒ Object
- #execute(parallelism: 1) ⇒ Object
- #failed? ⇒ Boolean
- #failed_commands ⇒ Object
-
#initialize(commands) ⇒ CommandRunner
constructor
A new instance of CommandRunner.
- #success? ⇒ Boolean
- #successful_commands ⇒ Object
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_commands ⇒ Object
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 |
#duration ⇒ Object
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
25 26 27 |
# File 'lib/peer_commander/command_runner.rb', line 25 def failed? !success? end |
#failed_commands ⇒ Object
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
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_commands ⇒ Object
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 |