public async Task <IResultModel> Delete(Guid id) { var entity = await _repository.FindEntityAsync(id); if (entity == null) { return(ResultModel.NotExists); } if (entity.Status != JobStatus.Stop && entity.Status != JobStatus.Completed) { var jobKey = new JobKey(entity.TaskCode, entity.Group); await _quartzServer.DeleteJob(jobKey); } int result = await _repository.DeleteAsync(id); if (result > 0) { return(ResultModel.Success()); } else { return(ResultModel.Failed()); } }
public async Task <IResultModel> Update(JobUpdateModel model) { var entity = await _repository.GetAsync(model.Id); if (entity == null) { return(ResultModel.Failed()); } _mapper.Map(model, entity); entity.JobKey = $"{model.Group}.{model.Code}"; entity.EndDate = entity.EndDate.AddDays(1); if (await _repository.Exists(entity)) { return(ResultModel.Failed($"当前任务组{entity.Group}已存在任务编码${entity.Code}")); } //如果任务不是停止或者已完成,先删除在添加 if (entity.Status != JobStatus.Stop && entity.Status != JobStatus.Completed) { var jobKey = new JobKey(entity.Name, entity.Group); await _quartzServer.DeleteJob(jobKey); var result = await AddJob(entity, entity.Status == JobStatus.Running); if (!result.Successful) { return(result); } } return(ResultModel.Result(await _repository.UpdateAsync(entity))); }
public async Task <IResultModel> Update(JobUpdateModel model) { var entity = await _repository.GetAsync(model.Id); if (entity == null) { return(ResultModel.Failed("任务不存在")); } var oldStatus = entity.Status; var oldJobKey = new JobKey(entity.Name, entity.Group); _mapper.Map(model, entity); entity.JobKey = $"{model.Group}.{model.Code}"; entity.EndDate = entity.EndDate.AddDays(1); if (await _repository.Exists(entity)) { return(ResultModel.Failed($"当前任务组{entity.Group}已存在任务编码${entity.Code}")); } using (var tran = _repository.BeginTransaction()) { //未运行状态修改为暂停 if (oldStatus != JobStatus.Running) { entity.Status = JobStatus.Pause; } //如果不是未完成的任务,需要先从调度服务中删除任务 if (oldStatus != JobStatus.Completed) { await _quartzServer.DeleteJob(oldJobKey); } if (await _repository.UpdateAsync(entity, tran)) { var result = await AddJob(entity, entity.Status == JobStatus.Running); if (!result.Successful) { return(result); } tran.Commit(); return(ResultModel.Success()); } } return(ResultModel.Failed("添加失败")); }
public async Task <IResultModel> Update(JobUpdateModel model) { var entity = await _repository.GetAsync(model.Id); if (entity == null) { return(ResultModel.Failed("������")); } var oldStatus = entity.Status; var oldJobKey = new JobKey(entity.Name, entity.Group); _mapper.Map(model, entity); entity.JobKey = $"{model.Group}.{model.Code}"; entity.EndDate = entity.EndDate.AddDays(1); if (await _repository.Exists(entity)) { return(ResultModel.Failed($"��ǰ������{entity.Group}�Ѵ����������${entity.Code}")); } using (var uow = _dbContext.NewUnitOfWork()) { //δ����״̬��Ϊ��ͣ if (oldStatus != JobStatus.Running) { entity.Status = JobStatus.Pause; } //�������δ��ɵ�������Ҫ�ȴӵ��ȷ�����ɾ������ if (oldStatus != JobStatus.Completed) { await _quartzServer.DeleteJob(oldJobKey); } if (await _repository.UpdateAsync(entity, uow)) { var result = await AddJob(entity, entity.Status == JobStatus.Running); if (!result.Successful) { return(result); } uow.Commit(); return(ResultModel.Success()); } } return(ResultModel.Failed("����ʧ��")); }
public async Task <IResultModel> Delete(string id) { var entity = await _jobRepository.FirstAsync(id); if (entity == null) { return(ResultModel.NotExists); } var jobKey = new JobKey(entity.Code, entity.JobGroup); await _quartzServer.DeleteJob(jobKey); var result = await _jobRepository.SoftDeleteAsync(entity); return(ResultModel.Result(result)); }