/// <summary> /// 恢复任务 /// </summary> /// <param name="crontabId">定时任务Id</param> public static void Resume(string crontabId) { JobKey jobKey = new JobKey(crontabId); if (_Scheduler.CheckExists(jobKey).Result) { _Scheduler.ResumeJob(jobKey).Wait(); } else { using (ICrontabStore crontabStore = ResolveMediator.ResolveOptional <ICrontabStore>()) { if (crontabStore != null) { ICrontab crontab = crontabStore.Get <ICrontab>(crontabId); if (crontab != null) { ScheduleMediator.Schedule(crontab); } else { throw new NullReferenceException($"Id为\"{crontabId}\"的任务不存在!"); } } } } }
/// <summary> /// 获取任务 /// </summary> /// <typeparam name="T">定时任务类型</typeparam> /// <param name="crontabId">定时任务Id</param> /// <returns>定时任务</returns> /// <remarks>需要CrontabStore持久化支持</remarks> public static T GetCrontab <T>(string crontabId) where T : ICrontab { using (ICrontabStore crontabStore = ResolveMediator.ResolveOptional <ICrontabStore>()) { if (crontabStore == null) { throw new NotImplementedException("未注册持久化存储提供者!"); } T crontab = crontabStore.Get <T>(crontabId); return(crontab); } }