Class: SSHKit::Runner::Parallel

Inherits:
Abstract
  • Object
show all
Defined in:
lib/core_ext/sshkit/runner/parallel.rb

Instance Attribute Summary

Attributes inherited from Abstract

#backends

Instance Method Summary collapse

Methods inherited from Abstract

#active_backend, active_backend, #active_backend=, active_backend=, #send_cmd

Instance Method Details

#do_it(&block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/core_ext/sshkit/runner/parallel.rb', line 6

def do_it( &block)
  threads = []
  backends.each do |host|
    threads << Thread.new(host) do |h|
      begin

        self.active_backend = h
        block.call(h.host)

      rescue Exception => e
        e2 = ExecuteError.new e
        raise e2, "Exception while executing on host #{h}: #{e.message}"
      ensure
        self.active_backend = nil
      end
    end
  end
  threads.map(&:join)
end