Class: Trooper::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/trooper/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strategy, config) ⇒ Runner

Public: initialize a new Runner.

strategy - A Trooper::Strategy object to execute. config - A Trooper::Configuration object to use for deployment.

Examples

Runner.new(<Strategy>, <Configuration>) # => <Runner>

Returns a new Runner object.



18
19
20
21
# File 'lib/trooper/runner.rb', line 18

def initialize(strategy, config)
  @strategy, @config = strategy, config
  @list = strategy.list config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/trooper/runner.rb', line 6

def config
  @config
end

#listObject (readonly)

Returns the value of attribute list.



6
7
8
# File 'lib/trooper/runner.rb', line 6

def list
  @list
end

#strategyObject (readonly)

Returns the value of attribute strategy.



6
7
8
# File 'lib/trooper/runner.rb', line 6

def strategy
  @strategy
end

Instance Method Details

#executeObject

Public: Executes the strategy across mutiple hosts logging output as it goes.

Examples

@runner.execute # => true

Returns a boolean.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/trooper/runner.rb', line 30

def execute
  Trooper.logger.debug "Configuration\n#{config}"
  Trooper.logger.strategy strategy.description
  successful = nil
  
  hosts.each do |host|
    begin
      Trooper.logger.info "\e[4mRunning on #{host}\n"

      list.each do |strategy_name, type, name|
        # strategy_name, type, name
        commands, options = build_commands strategy_name, type, name
        runner_execute! host, commands, options if commands
      end

      successful = true
      Trooper.logger.success "\e[4mAll Actions Completed\n"
    rescue Exception => e
      Trooper.logger.error "#{e.class.to_s} : #{e.message}\n\n#{e.backtrace.join("\n")}"

      successful = false
      break #stop commands running on other servers
    ensure
      host.close
    end
  end
  
  successful
end