public async Task <IResultModel> Add(JobAddModel model) { var entity = _mapper.Map <JobEntity>(model); entity.JobKey = $"{model.Group}.{model.Code}"; entity.Status = JobStatus.Pause;//Ĭ�����Ӻ���ͣ����Ҫ�ֶ����� entity.EndDate = entity.EndDate.AddDays(1); if (await _repository.Exists(entity)) { return(ResultModel.Failed($"��ǰ������{entity.Group}�Ѵ����������${entity.Code}")); } using (var uow = _dbContext.NewUnitOfWork()) { if (await _repository.AddAsync(entity, uow)) { var result = await AddJob(entity); if (!result.Successful) { return(result); } uow.Commit(); return(ResultModel.Success()); } } return(ResultModel.Failed("����ʧ��")); }
public async Task <IResultModel> AddHttpJob(JobHttpAddModel model) { var entity = _mapper.Map <JobEntity>(model); entity.JobKey = $"{model.Group}.{model.Code}"; entity.Status = JobStatus.Stop; entity.EndDate = entity.EndDate.AddDays(1); //固定的任务类 entity.JobClass = _httpJobClass; entity.JobType = JobType.Http; if (await _repository.Exists(entity)) { return(ResultModel.Failed($"当前任务组{entity.Group}已存在任务编码${entity.Code}")); } //是否立即启动 if (model.Start) { var result = await AddJob(entity); if (!result.Successful) { return(result); } entity.Status = JobStatus.Running; } using var uow = _dbContext.NewUnitOfWork(); //添加job if (await _repository.AddAsync(entity, uow)) { var httpJob = _mapper.Map <JobHttpEntity>(model); httpJob.JobId = entity.Id; if (model.HeaderList != null && model.HeaderList.Any()) { httpJob.Headers = JsonSerializer.Serialize(model.HeaderList); } //添加job的http信息 if (await _jobHttpRepository.AddAsync(httpJob)) { uow.Commit(); return(ResultModel.Success()); } } return(ResultModel.Failed()); }