码迷,mamicode.com
首页 > Web开发 > 详细

Quartz.Net系列(八):Trigger之CalendarIntervalScheduleBuilder详解

时间:2020-06-20 15:51:29      阅读:73      评论:0      收藏:0      [点我收藏+]

标签:interval   trigger   color   produce   定时   oca   produced   local   with   

所有方法图

技术图片

 

 CalendarIntervalScheduleBuilder方法

在SimpleScheduleBuilder基础上实现了日、周、月、年

WithInterval:指定要生成触发器的时间单位和间隔。

WithIntervalInHours:指定要生成触发器的间隔按小时来

WithIntervalInMinutes:指定要生成触发器的间隔按分钟来

WithIntervalInSeconds:指定要生成触发器的间隔按秒来

WithIntervalInDays:指定要生成触发器的间隔按日来

WithIntervalInWeeks:指定要生成触发器的间隔按周来

WithIntervalInMonths:指定要生成触发器的间隔按月来

WithIntervalInYears:指定要生成触发器的间隔按年来

            var trigger = TriggerBuilder.Create().WithCalendarIntervalSchedule(c=>c .WithInterval(1, IntervalUnit.Millisecond)
                                                                                    .WithIntervalInSeconds(1)
                                                                                    .WithIntervalInMinutes(1)
                                                                                    .WithIntervalInHours(1)
                                                                                    .WithIntervalInDays(1)
                                                                                    .WithIntervalInWeeks(1)
                                                                                    .WithIntervalInMonths(1)
                                                                                    .WithIntervalInYears(1)).Build();

注:按最后一个设定时间为准

最后指定给字段interval和intervalUnit,那么前面就会覆盖

在不指定间隔的时候默认是1,间隔单位是一天

    public class CalendarIntervalScheduleBuilder : ScheduleBuilder<ICalendarIntervalTrigger>
    {
        private int interval = 1;
        private IntervalUnit intervalUnit = IntervalUnit.Day;

        private int misfireInstruction = MisfireInstruction.SmartPolicy;
        private TimeZoneInfo timeZone;
        private bool preserveHourOfDayAcrossDaylightSavings;
        private bool skipDayIfHourDoesNotExist;
    }

 

 

技术图片

 

 

    /// <summary>
    /// Supported interval units used by <see cref="ICalendarIntervalTrigger" />.
    /// </summary>
    public enum IntervalUnit
    {
        Millisecond,
        Second,
        Minute,
        Hour,
        Day,
        Week,
        Month,
        Year
    }

 

 

       /// <summary>
        /// Specify the time unit and interval for the Trigger to be produced.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="interval">the interval at which the trigger should repeat.</param>
        /// <param name="unit"> the time unit (IntervalUnit) of the interval.</param>
        /// <returns>the updated CalendarIntervalScheduleBuilder</returns>
        /// <seealso cref="ICalendarIntervalTrigger.RepeatInterval" />
        /// <seealso cref="ICalendarIntervalTrigger.RepeatIntervalUnit" />
        public CalendarIntervalScheduleBuilder WithInterval(int interval, IntervalUnit unit)
        {
            ValidateInterval(interval);
            this.interval = interval;
            intervalUnit = unit;
            return this;
        }

        /// <summary>
        /// Specify an interval in the IntervalUnit.SECOND that the produced
        /// Trigger will repeat at.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="intervalInSeconds">the number of seconds at which the trigger should repeat.</param>
        /// <returns>the updated CalendarIntervalScheduleBuilder</returns>
        /// <seealso cref="ICalendarIntervalTrigger.RepeatInterval" />
        /// <seealso cref="ICalendarIntervalTrigger.RepeatIntervalUnit" />
        public CalendarIntervalScheduleBuilder WithIntervalInSeconds(int intervalInSeconds)
        {
            ValidateInterval(intervalInSeconds);
            interval = intervalInSeconds;
            intervalUnit = IntervalUnit.Second;
            return this;
        }

        /// <summary>
        /// Specify an interval in the IntervalUnit.MINUTE that the produced
        /// Trigger will repeat at.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="intervalInMinutes">the number of minutes at which the trigger should repeat.</param>
        /// <returns>the updated CalendarIntervalScheduleBuilder</returns>
        /// <seealso cref="ICalendarIntervalTrigger.RepeatInterval" />
        /// <seealso cref="ICalendarIntervalTrigger.RepeatIntervalUnit" />
        public CalendarIntervalScheduleBuilder WithIntervalInMinutes(int intervalInMinutes)
        {
            ValidateInterval(intervalInMinutes);
            interval = intervalInMinutes;
            intervalUnit = IntervalUnit.Minute;
            return this;
        }

        /// <summary>
        /// Specify an interval in the IntervalUnit.HOUR that the produced
        /// Trigger will repeat at.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="intervalInHours">the number of hours at which the trigger should repeat.</param>
        /// <returns>the updated CalendarIntervalScheduleBuilder</returns>
        /// <seealso cref="ICalendarIntervalTrigger.RepeatInterval" />
        /// <seealso cref="ICalendarIntervalTrigger.RepeatIntervalUnit" />
        public CalendarIntervalScheduleBuilder WithIntervalInHours(int intervalInHours)
        {
            ValidateInterval(intervalInHours);
            interval = intervalInHours;
            intervalUnit = IntervalUnit.Hour;
            return this;
        }

        /// <summary>
        /// Specify an interval in the IntervalUnit.DAY that the produced
        /// Trigger will repeat at.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="intervalInDays">the number of days at which the trigger should repeat.</param>
        /// <returns>the updated CalendarIntervalScheduleBuilder</returns>
        /// <seealso cref="ICalendarIntervalTrigger.RepeatInterval" />
        /// <seealso cref="ICalendarIntervalTrigger.RepeatIntervalUnit" />
        public CalendarIntervalScheduleBuilder WithIntervalInDays(int intervalInDays)
        {
            ValidateInterval(intervalInDays);
            interval = intervalInDays;
            intervalUnit = IntervalUnit.Day;
            return this;
        }

        /// <summary>
        /// Specify an interval in the IntervalUnit.WEEK that the produced
        /// Trigger will repeat at.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="intervalInWeeks">the number of weeks at which the trigger should repeat.</param>
        /// <returns>the updated CalendarIntervalScheduleBuilder</returns>
        /// <seealso cref="ICalendarIntervalTrigger.RepeatInterval" />
        /// <seealso cref="ICalendarIntervalTrigger.RepeatIntervalUnit" />
        public CalendarIntervalScheduleBuilder WithIntervalInWeeks(int intervalInWeeks)
        {
            ValidateInterval(intervalInWeeks);
            interval = intervalInWeeks;
            intervalUnit = IntervalUnit.Week;
            return this;
        }

        /// <summary>
        /// Specify an interval in the IntervalUnit.MONTH that the produced
        /// Trigger will repeat at.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="intervalInMonths">the number of months at which the trigger should repeat.</param>
        /// <returns>the updated CalendarIntervalScheduleBuilder</returns>
        /// <seealso cref="ICalendarIntervalTrigger.RepeatInterval" />
        /// <seealso cref="ICalendarIntervalTrigger.RepeatIntervalUnit" />
        public CalendarIntervalScheduleBuilder WithIntervalInMonths(int intervalInMonths)
        {
            ValidateInterval(intervalInMonths);
            interval = intervalInMonths;
            intervalUnit = IntervalUnit.Month;
            return this;
        }

        /// <summary>
        /// Specify an interval in the IntervalUnit.YEAR that the produced
        /// Trigger will repeat at.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="intervalInYears">the number of years at which the trigger should repeat.</param>
        /// <returns>the updated CalendarIntervalScheduleBuilder</returns>
        /// <seealso cref="ICalendarIntervalTrigger.RepeatInterval" />
        /// <seealso cref="ICalendarIntervalTrigger.RepeatIntervalUnit" />
        public CalendarIntervalScheduleBuilder WithIntervalInYears(int intervalInYears)
        {
            ValidateInterval(intervalInYears);
            interval = intervalInYears;
            intervalUnit = IntervalUnit.Year;
            return this;
        }

InTimeZone:设置时区

 var trigger = TriggerBuilder.Create().WithCalendarIntervalSchedule(c => c.InTimeZone(TimeZoneInfo.Local)).Build();

 

Quartz.Net系列(八):Trigger之CalendarIntervalScheduleBuilder详解

标签:interval   trigger   color   produce   定时   oca   produced   local   with   

原文地址:https://www.cnblogs.com/vic-tory/p/13168866.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!