Exemplo n.º 1
0
        /// <summary>
        /// 处理单个作业
        /// </summary>
        /// <param name="job">Job.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        private void ProcessJob(JobBase job, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();

            // 重新获取作业最新信息,因为作业支持多个并行异步处理,开始处理此作业时,之前拿到的作业信息可能已经过时了
            job = _cluster.GetJobRecord(job.Name, job.Id);

            // 明确为计划制定失败、任务合并失败、任务执行失败的不应该重试,应该先找找原因。

            // 处理任务计划中下线的工人
            if (job.Status == EnumJobRecordStatus.PlanMaked ||
                job.Status == EnumJobRecordStatus.TaskExecuting ||
                job.Status == EnumJobRecordStatus.Canceling ||
                job.Status == EnumJobRecordStatus.TaskCompleted)
            {
                job.ReplaceTaskPlanOfflineWorker(cancellationToken);
            }

            // 待处理的作业肯定需要处理
            if (job.Status == EnumJobRecordStatus.Pending)
            {
                job.CreateProductionPlan(cancellationToken);
            }

            // 正在制定计划的作业,可能Swift停止运行导致的
            if (job.Status == EnumJobRecordStatus.PlanMaking)
            {
                LogWriter.Write("作业为计划制定中状态,将检查对应的进程:" + job.BusinessId, Log.LogLevel.Info);

                if (CheckPlanMakingJob(job, cancellationToken))
                {
                    LogWriter.Write("开始监控运行作业计划制定");
                    job.MointorRunJobSplit(cancellationToken);
                }
            }

            // 任务正在执行或都处理完成的作业:更新作业状态为任务已全部完成或任务结果已全部同步
            if (job.Status == EnumJobRecordStatus.PlanMaked ||
                job.Status == EnumJobRecordStatus.TaskExecuting ||
                job.Status == EnumJobRecordStatus.TaskCompleted ||
                job.Status == EnumJobRecordStatus.Canceling)
            {
                job.CheckTaskRunStatus(cancellationToken);
            }

            // 任务正在执行或都处理完成的作业:同步任务结果
            if (job.Status == EnumJobRecordStatus.TaskExecuting ||
                job.Status == EnumJobRecordStatus.TaskCompleted)
            {
                job.SyncTaskResult(cancellationToken);
            }

            // 合并任务同步完成的作业:合并全部任务结果
            if (job.Status == EnumJobRecordStatus.TaskSynced)
            {
                job.MergeTaskResult(cancellationToken);
            }

            // 正在合并结果的作业,可能Swift停止运行导致的
            if (job.Status == EnumJobRecordStatus.TaskMerging)
            {
                LogWriter.Write("作业为任务结果合并中状态,将检查对应的进程:" + job.BusinessId, Log.LogLevel.Info);

                if (CheckTaskMergingJob(job, cancellationToken))
                {
                    LogWriter.Write("开始监控运行任务结果合并");
                    job.MointorRunCollectTaskResult(cancellationToken);
                }
            }
        }