Module: SSHKit::Runner::Parallel::CompleteAll

Included in:
SSHKit::Runner::Parallel
Defined in:
lib/dash/sshkit_with_ext.rb

Overview

SSHKit joins the threads in sequence and fails on the first error it encounters, which means that we wait threads before the first failure to complete but not for ones after.

We'll patch it to wait for them all to complete, and to record all the threads that errored so we can see when a problem occurs on multiple hosts.

Instance Method Summary collapse

Instance Method Details

#executeObject



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/dash/sshkit_with_ext.rb', line 226

def execute
  threads = hosts.map do |host|
    Thread.new(host) do |h|
      Thread.current.report_on_exception = false
      backend(h, &block).run
    rescue ::StandardError => e
      e2 = SSHKit::Runner::ExecuteError.new e
      raise e2, "Exception while executing #{host.user ? "as #{host.user}@" : "on host "}#{host}: #{e.message}"
    end
  end

  exceptions = []
  threads.each do |t|
    begin
      t.join
    rescue SSHKit::Runner::ExecuteError => e
      exceptions << e
    end
  end
  if exceptions.one?
    raise exceptions.first
  elsif exceptions.many?
    raise exceptions.first, [ "Exceptions on #{exceptions.count} hosts:", exceptions.map(&:message) ].join("\n")
  end
end