private static async Task ProcessJobs(string hostname, CancellationToken cancellationToken) { Process process = null; string tempDir = null; while (!cancellationToken.IsCancellationRequested) { var allJobs = _jobs.GetAll(); var job = allJobs.FirstOrDefault(); if (job != null) { if (job.State == ServerState.Waiting) { // TODO: Race condition if DELETE is called during this code try { Log.WriteLine($"Starting job '{job.Id}' with scenario '{job.Scenario}'"); job.State = ServerState.Starting; Debug.Assert(tempDir == null); tempDir = GetTempDir(); var benchmarksDir = CloneAndRestore(tempDir, job); Debug.Assert(process == null); process = StartProcess(hostname, Path.Combine(tempDir, benchmarksDir), job); } catch (Exception e) { Log.WriteLine($"Error starting job '{job.Id}': {e}"); if (tempDir != null) { DeleteDir(tempDir); tempDir = null; } job.State = ServerState.Failed; continue; } } else if (job.State == ServerState.Deleting) { Log.WriteLine($"Deleting job '{job.Id}' with scenario '{job.Scenario}'"); if (process != null) { // TODO: Replace with managed xplat version of kill process tree ProcessUtil.Run("taskkill.exe", $"/f /t /pid {process.Id}", throwOnError: false); process.Dispose(); process = null; } if (tempDir != null) { DeleteDir(tempDir); tempDir = null; } _jobs.Remove(job.Id); } } await Task.Delay(100); } }
private static ProcessResult RunGitCommand(string path, string command, TimeSpan?timeout, bool throwOnError = true, int retries = 0) { return(ProcessUtil.RetryOnException(retries, () => ProcessUtil.Run("git", command, timeout, workingDirectory: path, throwOnError: throwOnError, captureOutput: true, captureError: true))); }
private static ProcessResult RunGitCommand(string path, string command, bool throwOnError = true) { return(ProcessUtil.Run("git", command, workingDirectory: path, throwOnError: throwOnError)); }