Class: Ndo::MultiCommand

Inherits:
Object
  • Object
show all
Includes:
Procrastinate
Defined in:
lib/ndo/multi_command.rb

Overview

A class to execute a command on a list of hosts in parallel; allows access to results and is thus a) multi threaded and b) Ruby 1.9.2 only.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, hosts) ⇒ MultiCommand

Returns a new instance of MultiCommand.



17
18
19
20
# File 'lib/ndo/multi_command.rb', line 17

def initialize(command, hosts)
  @command  = command
  @hosts    = hosts
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



14
15
16
# File 'lib/ndo/multi_command.rb', line 14

def command
  @command
end

#hostsObject (readonly)

Returns the value of attribute hosts.



15
16
17
# File 'lib/ndo/multi_command.rb', line 15

def hosts
  @hosts
end

Instance Method Details

#runObject

Runs the command on all hosts. Returns a result collection.



24
25
26
27
28
29
30
31
# File 'lib/ndo/multi_command.rb', line 24

def run
  proxy = Procrastinate.proxy(self)

  Ndo::Results.new.tap { |results| 
    hosts.each { |host|
      results.store host, proxy.run_for_host(host)
    }}
end

#run_for_host(host) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/ndo/multi_command.rb', line 33

def run_for_host(host)
  begin
    Ndo::Host.new(host).run(@command).first
  rescue => b
    "Failure: #{b}"
  end
end