private int RunThreeTimes(string commandWithArguments, string workingDirectory, TimeSpan timeout, RetryStrategy retryStrategy = RetryStrategy.IfTimeout) { int exitCode = RunOnce(commandWithArguments, workingDirectory, timeout); int times = 2; while (times-- > 0 && NeedRunAgain(retryStrategy, exitCode)) { if (HasTimeout) { timeout = TimoutHelper.IncreaceTimeout(timeout); } exitCode = RunOnce(commandWithArguments, workingDirectory, timeout); } return(exitCode); }
private int RunThreeTimes(string commandWithArguments, string workingDirectory, TimeSpan timeout, RetryStrategy retryStrategy = RetryStrategy.IfTimeout) { int exitCode = RunOnce(commandWithArguments, workingDirectory, timeout); int times = 2; while (times-- > 0 && NeedRunAgain(retryStrategy, exitCode)) { if (HasTimeout) { timeout = TimoutHelper.IncreaceTimeout(timeout); } exitCode = RunOnce(commandWithArguments, workingDirectory, timeout); log.Debug($"EXECUTED {startInfo.FileName} {startInfo.Arguments} in {workingDirectory} with exitCode {exitCode} and retryStrategy {retryStrategy}"); } return(exitCode); }
private int RunThreeTimes(string commandWithArguments, string workingDirectory, TimeSpan timeout) { int result = RunOnce(commandWithArguments, workingDirectory, timeout); if (!HasTimeout) { return(result); } timeout = TimoutHelper.IncreaceTimeout(timeout); int times = 2; while (times-- > 0 && HasTimeout) { result = RunOnce(commandWithArguments, workingDirectory, timeout); } return(result); }
private static void UpdateGitPackage(Package package) { var runner = new ShellRunner(Log); var timeout = TimeSpan.FromMinutes(1); for (int i = 0; i < 3; i++) { using (var tempDir = new TempDirectory()) { if (runner.RunOnce( $"git clone {package.Url} {Path.Combine(tempDir.Path, package.Name)}", Directory.GetCurrentDirectory(), timeout) != 0) { if (runner.HasTimeout && i < 2) { timeout = TimoutHelper.IncreaceTimeout(timeout); continue; } throw new CementException( $"Failed to update package {package.Name}:\n{runner.Output}\nError message:\n{runner.Errors}\n" + $"Ensure that command 'git clone {package.Url}' works in cmd"); } lock (Helper.PackageLockObject) { if (!Directory.Exists(Helper.GetGlobalCementDirectory())) { Directory.CreateDirectory(Helper.GetGlobalCementDirectory()); } File.Copy(Path.Combine(tempDir.Path, package.Name, "modules"), Helper.GetPackagePath(package.Name), true); } break; } } }