Class: Scripted::Running::RunCommands
- Inherits:
-
Object
- Object
- Scripted::Running::RunCommands
- Defined in:
- lib/scripted/running/run_commands.rb
Instance Attribute Summary collapse
-
#ended_at ⇒ Object
readonly
Returns the value of attribute ended_at.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#runtime ⇒ Object
readonly
Returns the value of attribute runtime.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
Instance Method Summary collapse
- #completed ⇒ Object
- #done(command) ⇒ Object
- #executed? ⇒ Boolean
- #failed? ⇒ Boolean
- #halt!(command) ⇒ Object
- #halted? ⇒ Boolean
-
#initialize(logger) ⇒ RunCommands
constructor
A new instance of RunCommands.
- #run(commands) ⇒ Object
- #running? ⇒ Boolean
Constructor Details
#initialize(logger) ⇒ RunCommands
Returns a new instance of RunCommands.
9 10 11 12 13 14 |
# File 'lib/scripted/running/run_commands.rb', line 9 def initialize(logger) @logger = logger @executed = false @halted = false @running = false end |
Instance Attribute Details
#ended_at ⇒ Object (readonly)
Returns the value of attribute ended_at.
7 8 9 |
# File 'lib/scripted/running/run_commands.rb', line 7 def ended_at @ended_at end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
5 6 7 |
# File 'lib/scripted/running/run_commands.rb', line 5 def logger @logger end |
#runtime ⇒ Object (readonly)
Returns the value of attribute runtime.
7 8 9 |
# File 'lib/scripted/running/run_commands.rb', line 7 def runtime @runtime end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
7 8 9 |
# File 'lib/scripted/running/run_commands.rb', line 7 def started_at @started_at end |
Instance Method Details
#completed ⇒ Object
32 33 34 |
# File 'lib/scripted/running/run_commands.rb', line 32 def completed @completed ||= [] end |
#done(command) ⇒ Object
36 37 38 39 |
# File 'lib/scripted/running/run_commands.rb', line 36 def done(command) logger.done(command) completed << command end |
#executed? ⇒ Boolean
58 59 60 |
# File 'lib/scripted/running/run_commands.rb', line 58 def executed? @executed end |
#failed? ⇒ Boolean
41 42 43 |
# File 'lib/scripted/running/run_commands.rb', line 41 def failed? completed.any?(&:failed?) end |
#halt!(command) ⇒ Object
45 46 47 48 |
# File 'lib/scripted/running/run_commands.rb', line 45 def halt!(command) logger.halted(command) @halted = true end |
#halted? ⇒ Boolean
50 51 52 |
# File 'lib/scripted/running/run_commands.rb', line 50 def halted? @halted end |
#run(commands) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/scripted/running/run_commands.rb', line 16 def run(commands) logged commands do per_parallel_id commands do |parallel_commands| threads = [] parallel_commands.each do |command| if should_execute?(command) threads << Thread.new do command.execute!(self) end end end threads.each(&:join) end end end |
#running? ⇒ Boolean
54 55 56 |
# File 'lib/scripted/running/run_commands.rb', line 54 def running? @running end |