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
#execute ⇒ Object
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/dash/sshkit_with_ext.rb', line 289 def execute # A new thread starts with none of its parent's thread-locals, so the timing entry # has to be handed over explicitly or every command run on a host would be # attributed to no phase at all. timing_entry = DashTimings.current_entry threads = hosts.map do |host| Thread.new(host) do |h| Thread.current.report_on_exception = false DashTimings.current_entry = timing_entry 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.}" 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 |