Esempio n. 1
0
        /// <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}\"的任务不存在!");
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 恢复全部任务
        /// </summary>
        /// <remarks>需要CrontabStore持久化支持</remarks>
        public static void ResumeAll()
        {
            using (ICrontabStore crontabStore = ResolveMediator.ResolveOptional <ICrontabStore>())
            {
                if (crontabStore == null)
                {
                    throw new NotImplementedException("未注册持久化存储提供者!");
                }

                IList <ICrontab> crontabs = crontabStore.FindAll();

                foreach (ICrontab crontab in crontabs)
                {
                    ScheduleMediator.Schedule(crontab);
                }
            }
        }
        /// <summary>
        /// 异常恢复
        /// </summary>
        /// <remarks>需要CrontabStore持久化支持</remarks>
        public static void Recover()
        {
            using (ICrontabStore crontabStore = ResolveMediator.ResolveOptional <ICrontabStore>())
            {
                if (crontabStore == null)
                {
                    throw new NotImplementedException("未注册持久化存储提供者!");
                }

                IList <ICrontab>       crontabs          = crontabStore.FindAll();
                IEnumerable <ICrontab> scheduledCrontabs = crontabs.Where(x => x.Status == CrontabStatus.Scheduled);

                foreach (ICrontab crontab in scheduledCrontabs)
                {
                    ScheduleMediator.Schedule(crontab);
                }
            }
        }