public DataRes <bool> Resume(int id) { var res = new DataRes <bool>() { code = ResCode.Success, data = true }; using (var uow = _uowProvider.CreateUnitOfWork()) { var repository = uow.GetRepository <ResSchedule>(); //根据任务编号获取任务详情 var model = repository.Get(id); //恢复指定任务 var result = QuartzHelper.ResumeScheduleAsync(model); if (result.Result.Code == 1000) { model.JobStatus = 1; model.WriteDate = DateTime.Now; var t10 = repository.Update(model); res.msg = result.Result.Msg; logger.Info($"任务已恢复:{model.JobGroup}-{model.JobName},{result.Result.Msg}"); } else { res.code = ResCode.Error; res.msg = result.Result.Msg; logger.Error($"任务恢复异常:{model.JobGroup}-{model.JobName},{result.Result.Msg}"); } } return(res); }
/// <summary> /// 程序启动将任务调度表里所有状态为 执行中 任务启动起来 /// </summary> /// <param name="serviceCollection"></param> /// <returns></returns> public static async System.Threading.Tasks.Task <IServiceCollection> AddJobServiceAsync(this IServiceCollection serviceCollection) { serviceCollection.BuildServiceProvider().RegisterServiceProvider(); var jobListner = ServiceCollectionExtension.Get <IJobListener>(); var jobCenter = ServiceCollectionExtension.Get <ISchedulerCenter>(); var uowProvider = ServiceCollectionExtension.Get <IUowProvider>(); using (var uow = uowProvider.CreateUnitOfWork()) { var repository = uow.GetRepository <ResSchedule>(); var schedule = repository.Query(x => x.JobStatus.Equals(1)); QuartzHelper._scheduler.Start(); foreach (var resSchedule in schedule) { if (!string.IsNullOrEmpty(resSchedule.AssemblyName)) { //var scheduleEntity = Mapper<ResSchedule, ScheduleEntity>.Map(item); //ScheduleManage.Instance.AddScheduleList(scheduleEntity); //var result = jobCenter.RunScheduleJob<ScheduleManage>(item.JobGroup, item.JobName).Result; QuartzHelper.ResumeScheduleAsync(resSchedule); } } } return(serviceCollection); }
public DataRes <bool> Execute(int id) { var res = new DataRes <bool>() { code = ResCode.Success, data = true }; using (var uow = _uowProvider.CreateUnitOfWork()) { var repository = uow.GetRepository <ResSchedule>(); var model = repository.Get(id); //var scheduleEntity = Mapper<ResSchedule, ScheduleEntity>.Map(model); ////给IJob设置参数 //scheduleEntity.Agrs = new Dictionary<string, object> { { "orderId", id } }; //ScheduleManage.Instance.AddScheduleList(scheduleEntity); //// 运行任务调度 BaseQuartzNetResult result; result = QuartzHelper.ResumeScheduleAsync(model).Result; //if (model.TriggerType == 0) //{ // result = _schedulerCenter.RunScheduleJob<ScheduleManage, SubmitJobTask>(model.JobGroup, model.JobName).Result; //} //else //{ // result = _schedulerCenter.RunScheduleJob<ScheduleManage>(model.JobGroup, model.JobName).Result; //} Console.Out.WriteLineAsync("任务执行状态:" + result.Msg); if (result.Code == 1000) { model.JobStatus = 1; model.WriteDate = DateTime.Now; var t10 = repository.Update(model); res.msg = result.Msg; logger.Info($"任务执行中:{model.JobGroup}-{model.JobName},{result.Msg}"); } else { res.code = ResCode.Error; res.msg = result.Msg; logger.Error($"任务执行失败:{model.JobGroup}-{model.JobName},{result.Msg}"); } } return(res); }