/// <summary> /// 启动 /// </summary> /// <returns></returns> public async Task Start() { //执行中的任务 var jobList = _dbContext.QuarztSchedule.Where(o => o.RunStatus == (int)JobStatus.执行任务中).ToList() .Select(item => _mapper.Map <QuarztScheduleMapping>(item)).ToList(); jobList.ForEach(async item => { await _jobCenter.AddScheduleJobAsync(item); }); await Task.FromResult(0); }
/// <summary> /// 开启任务 /// </summary> /// <param name="id"></param> /// <returns></returns> public (bool Status, string Message) Start(Guid id) { var item = _dbContext.QuarztSchedule.Find(id); if (item == null) { return(Fail("任务不存在")); } var res = _jobCenter.AddScheduleJobAsync(_mapper.Map <QuarztScheduleMapping>(item)).Result; if (res.Status) { item.RunStatus = (int)JobStatus.执行任务中; _dbContext.SaveChanges(); } return(res); }