public async Task <IResultModel> Resume(Guid id) { var entity = await _repository.GetAsync(id); if (entity == null) { return(ResultModel.Failed("������")); } if (entity.Status != JobStatus.Running) { var oldStatus = entity.Status; entity.Status = JobStatus.Running; using (var uow = _dbContext.NewUnitOfWork()) { if (await _repository.UpdateAsync(entity, uow)) { try { //����ɵ�����������Ҫ���¼��뵽������ if (oldStatus == JobStatus.Completed) { if (entity.EndDate <= DateTime.Now) { return(ResultModel.Failed("����ʱЧ�ѹ���")); } var result = await AddJob(entity, true); if (!result.Successful) { return(result); } } else { var jobKey = new JobKey(entity.Code, entity.Group); await _quartzServer.ResumeJob(jobKey); } uow.Commit(); return(ResultModel.Success("������")); } catch (Exception ex) { _logger.LogError($"��������ʧ�ܣ�{ex}"); } } } } return(ResultModel.Failed("����ʧ��")); }
public async Task <IResultModel> Resume(Guid id) { var entity = await _repository.GetAsync(id); if (entity == null) { return(ResultModel.Failed("任务不存在")); } if (entity.Status != JobStatus.Running) { var oldStatus = entity.Status; entity.Status = JobStatus.Running; using (var tran = _repository.BeginTransaction()) { if (await _repository.UpdateAsync(entity)) { try { //已完成的任务,重启需要重新加入到调度中 if (oldStatus == JobStatus.Completed) { if (entity.EndDate <= DateTime.Now) { return(ResultModel.Failed("任务时效已过期")); } var result = await AddJob(entity, true); if (!result.Successful) { return(result); } } else { var jobKey = new JobKey(entity.Code, entity.Group); await _quartzServer.ResumeJob(jobKey); } tran.Commit(); return(ResultModel.Success("已启动")); } catch (Exception ex) { _logger.LogError($"任务启动失败:{ex}"); } } } } return(ResultModel.Failed("启动失败")); }
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()); }
public async Task <IResultModel> Resume(Guid id) { var entity = await _repository.FindEntityAsync(id); if (entity == null) { return(ResultModel.Failed()); } if (entity.Status == JobStatus.Running) { return(ResultModel.Failed("任务已启动,请刷新页面")); } //停止的或者已完成的任务,重启需要重新加入到调度中 if (entity.Status == JobStatus.Stop || entity.Status == JobStatus.Completed) { if (entity.EndDate <= DateTime.Now) { return(ResultModel.Failed("任务时效已过期")); } var result = await AddJob(entity, true); if (!result.Successful) { return(result); } } else { var jobKey = new JobKey(entity.TaskCode, entity.Group); await _quartzServer.ResumeJob(jobKey); } return(ResultModel.Success()); }