Module: SSHKit::Runner::Parallel::CompleteAll
- Included in:
- SSHKit::Runner::Parallel
- Defined in:
- lib/kamal/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
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/kamal/sshkit_with_ext.rb', line 115 def execute threads = hosts.map do |host| Thread.new(host) do |h| 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 |