Пример #1
0
        private bool StopLocalSparkJob(LocalBatchResult batch)
        {
            try
            {
                _logger.LogInformation($"Stopping local job with process id {batch.Id.ToString()}");
                var jobProcess = Process.GetProcessById(batch.Id);

                if (IsSparkJobProcess(jobProcess, batch))
                {
                    var result = jobProcess.CloseMainWindow();
                    // Kill the process if CloseMainWindow is not supported.
                    // This is true for linux where shellExecute is set to false
                    if (!result && !jobProcess.HasExited)
                    {
                        _logger.LogInformation($"Killing the process with id {jobProcess.Id}");
                        jobProcess.Kill();
                    }
                    return(true);
                }
            }
            catch (Exception ex)
            {
                // Its possible for job process to be stopped outside of the flow. Handle this case.
                _logger.LogWarning($"Job process is likely not running anymore. GetProcessById failed with msg: {ex.Message}");
            }

            return(false);
        }
Пример #2
0
 /// <summary>
 /// Check if the given process is same as the spark job process.
 /// </summary>
 /// <param name="jobProc"></param>
 /// <param name="batch"></param>
 /// <returns></returns>
 private bool IsSparkJobProcess(Process jobProc, LocalBatchResult batch)
 {
     // Compare process id and startTime to determine if the spark job that was started is same as the one passed in
     return(jobProc != null && !jobProc.HasExited && batch != null && jobProc.Id == batch.Id && jobProc.StartTime == batch.StartTime);
 }