Пример #1
0
        /// <summary>
        /// 获取全部任务列表
        /// </summary>
        /// <returns>定时任务列表</returns>
        /// <remarks>需要CrontabStore持久化支持</remarks>
        public static IList <ICrontab> FindAll()
        {
            using (ICrontabStore crontabStore = ResolveMediator.ResolveOptional <ICrontabStore>())
            {
                if (crontabStore == null)
                {
                    throw new NotImplementedException("未注册持久化存储提供者!");
                }

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

                return(crontabs);
            }
        }
Пример #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);
                }
            }
        }
Пример #3
0
        /// <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)
                {
                    Schedule(crontab);
                }
            }
        }