/// <summary> /// 清理脱离控制的执行任务进程 /// </summary> /// <param name="taskExecuteProcess">Task execute process.</param> private void CleanOutOfControlTaskExecuteProcess(IEnumerable <string[]> taskExecuteProcess) { LogWriter.Write("Manager不应该执行任务进程,他们都应该被Kill"); foreach (var processInfo in taskExecuteProcess) { var processId = int.Parse(processInfo[1]); var jobName = processInfo[2]; var jobId = processInfo[3]; var taskId = int.Parse(processInfo[4]); LogWriter.Write(string.Format("正在处理:{0},{1},{2}", jobName, jobId, taskId)); SwiftProcess.KillAbandonedTaskProcess(processId, jobName, jobId, taskId); } }
/// <summary> /// 清理脱离控制的执行任务进程 /// </summary> /// <param name="taskExecuteProcess">Task execute process.</param> private void CleanOutOfControlTaskExecuteProcess(IEnumerable <string[]> taskExecuteProcess, CancellationToken cancellationToken = default(CancellationToken)) { foreach (var processInfo in taskExecuteProcess) { var processId = int.Parse(processInfo[1]); var jobName = processInfo[2]; var jobId = processInfo[3]; var taskId = int.Parse(processInfo[4]); LogWriter.Write(string.Format("正在处理:{0},{1},{2}", jobName, jobId, taskId)); var jobRecord = _cluster.ConfigCenter.GetJobRecord(jobName, jobId, _cluster, cancellationToken); // 作业不存在了,看看任务进程还在不在 if (jobRecord == null) { LogWriter.Write("作业记录不存在了,尝试关闭废弃的任务进程"); SwiftProcess.KillAbandonedTaskProcess(processId, jobName, jobId, taskId); continue; } LogWriter.Write(string.Format("作业记录存在")); // 任务不是我的了,看看进程还在不在 var task = jobRecord.TaskPlan.Where(d => d.Key == _member.Id && d.Value.Any(t => t.Id == taskId)) .SelectMany(d => d.Value).FirstOrDefault(t => t.Id == taskId); if (task == null) { LogWriter.Write("任务被重新分走了,尝试关闭废弃的任务进程"); SwiftProcess.KillAbandonedTaskProcess(processId, jobName, jobId, taskId); continue; } LogWriter.Write(string.Format("任务存在")); // 任务非Executing状态,看看进程在不在 if (task.Status != EnumTaskStatus.Executing) { LogWriter.Write("任务非Executing状态,尝试关闭废弃的任务进程"); SwiftProcess.KillAbandonedTaskProcess(processId, jobName, jobId, taskId); continue; } LogWriter.Write(string.Format("任务在Executing状态,将继续运行")); } }