Ejemplo n.º 1
0
        public async Task <IResultModel> Resume(string id)
        {
            try
            {
                var entity = await _jobRepository.FirstAsync(id);

                if (entity == null)
                {
                    return(ResultModel.NotExists);
                }

                if (entity.Status == JobStatus.Running)
                {
                    return(ResultModel.Failed("任务已启动,请刷新页面"));
                }

                var jobKey = new JobKey(entity.Code, entity.JobGroup);

                var job = await _quartzServer.GetJob(jobKey);

                if (job == null)
                {
                    if (entity.EndTime <= DateTime.Now)
                    {
                        return(ResultModel.Failed("任务时效已过期"));
                    }

                    var result = await AddJob(entity, true);

                    if (!result.Successful)
                    {
                        return(result);
                    }
                }
                else
                {
                    await _quartzServer.ResumeJob(jobKey);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"重启任务失败,任务ID:{id},异常信息:{ex.Message}", ex);
                return(ResultModel.Failed(ex.Message));
            }

            return(ResultModel.Success());
        }