private static int Deploy(object script, IOperationTracker operationTracker, IReadOnlyList <string> nodeAddresses, IEnumerable <string> arguments, TimeSpan connectTimeout) { var method = FindDeployMethod(script); if (nodeAddresses.Count == 1) { return(DeployTo(script, method, operationTracker, nodeAddresses[0], arguments, connectTimeout)); } var tracker = new NodeTracker(operationTracker, nodeAddresses); Parallel.ForEach(nodeAddresses, nodeAddress => { var nodeTracker = tracker.Get(nodeAddress); try { DeployTo(script, method, nodeTracker, nodeAddress, arguments, connectTimeout); nodeTracker.Success(); } catch (Exception e) { // We want keep track of failures on individual nodes // and only rethrow those exceptions after everything's done. nodeTracker.Failed(e); } }); tracker.ThrowOnFailure(); return(0); }