Class: SSHKit::Runner::SafeParallel
- Inherits:
-
SafeSequential
- Object
- Sequential
- SafeSequential
- SSHKit::Runner::SafeParallel
- Defined in:
- lib/gaptool_client/runner.rb
Instance Attribute Summary collapse
-
#group_size ⇒ Object
writeonly
Sets the attribute group_size.
Attributes inherited from SafeSequential
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(hosts, options = nil, &block) ⇒ SafeParallel
constructor
A new instance of SafeParallel.
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, = nil, &block) super(hosts, , &block) @failed = Queue.new @succeeded = Queue.new end |
Instance Attribute Details
#group_size=(value) ⇒ Object
Sets the attribute group_size
39 40 41 |
# File 'lib/gaptool_client/runner.rb', line 39 def group_size=(value) @group_size = value end |
Instance Method Details
#execute ⇒ Object
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 |