Class: SSHKit::Runner::SafeParallel

Inherits:
SafeSequential show all
Defined in:
lib/gaptool_client/runner.rb

Instance Attribute Summary collapse

Attributes inherited from SafeSequential

#failed, #succeeded

Instance Method Summary collapse

Constructor Details

#initialize(hosts, options = nil, &block) ⇒ SafeParallel

Returns a new instance of SafeParallel.



41
42
43
44
45
# File 'lib/gaptool_client/runner.rb', line 41

def initialize(hosts, options = nil, &block)
  super(hosts, options, &block)
  @failed = Queue.new
  @succeeded = Queue.new
end

Instance Attribute Details

#group_size=(value) ⇒ Object

Sets the attribute group_size

Parameters:

  • value

    the value to set the attribute group_size to.



39
40
41
# File 'lib/gaptool_client/runner.rb', line 39

def group_size=(value)
  @group_size = value
end

Instance Method Details

#executeObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/gaptool_client/runner.rb', line 47

def execute
  hosts.each_slice(group_size).each do |slice|
    threads = []
    slice.each do |host|
      threads << Thread.new(host) do |h|
        begin
          backend(h, &block).run
          succeeded << host
        rescue => e
          failed << { host: host, error: e }
        end
      end
    end
    threads.map(&:join)
    return convert_results if failed.length > 0 && @on_errors == :exit
    sleep wait_interval
  end
  convert_results
end