Class: Scripted::Running::RunCommands

Inherits:
Object
  • Object
show all
Defined in:
lib/scripted/running/run_commands.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_atObject (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

#loggerObject (readonly)

Returns the value of attribute logger.



5
6
7
# File 'lib/scripted/running/run_commands.rb', line 5

def logger
  @logger
end

#runtimeObject (readonly)

Returns the value of attribute runtime.



7
8
9
# File 'lib/scripted/running/run_commands.rb', line 7

def runtime
  @runtime
end

#started_atObject (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

#completedObject



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

Returns:

  • (Boolean)


58
59
60
# File 'lib/scripted/running/run_commands.rb', line 58

def executed?
  @executed
end

#failed?Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


54
55
56
# File 'lib/scripted/running/run_commands.rb', line 54

def running?
  @running
end