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
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/kamal/sshkit_with_ext.rb', line 177 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 |