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

2021-02-02 17:15

阅读:679

标签: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
    {
        private int interval = 1;
        private IntervalUnit intervalUnit = IntervalUnit.Day;

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

 

 

技术图片

 

 

    /// 
    /// Supported interval units used by .
    /// 
    public enum IntervalUnit
    {
        Millisecond,
        Second,
        Minute,
        Hour,
        Day,
        Week,
        Month,
        Year
    }

 

 

       /// 
        /// Specify the time unit and interval for the Trigger to be produced.
        /// 
        /// 
        /// 
        /// the interval at which the trigger should repeat.
        ///  the time unit (IntervalUnit) of the interval.
        /// the updated CalendarIntervalScheduleBuilder
        /// 
        /// 
        public CalendarIntervalScheduleBuilder WithInterval(int interval, IntervalUnit unit)
        {
            ValidateInterval(interval);
            this.interval = interval;
            intervalUnit = unit;
            return this;
        }

        /// 
        /// Specify an interval in the IntervalUnit.SECOND that the produced
        /// Trigger will repeat at.
        /// 
        /// 
        /// 
        /// the number of seconds at which the trigger should repeat.
        /// the updated CalendarIntervalScheduleBuilder
        /// 
        /// 
        public CalendarIntervalScheduleBuilder WithIntervalInSeconds(int intervalInSeconds)
        {
            ValidateInterval(intervalInSeconds);
            interval = intervalInSeconds;
            intervalUnit = IntervalUnit.Second;
            return this;
        }

        /// 
        /// Specify an interval in the IntervalUnit.MINUTE that the produced
        /// Trigger will repeat at.
        /// 
        /// 
        /// 
        /// the number of minutes at which the trigger should repeat.
        /// the updated CalendarIntervalScheduleBuilder
        /// 
        /// 
        public CalendarIntervalScheduleBuilder WithIntervalInMinutes(int intervalInMinutes)
        {
            ValidateInterval(intervalInMinutes);
            interval = intervalInMinutes;
            intervalUnit = IntervalUnit.Minute;
            return this;
        }

        /// 
        /// Specify an interval in the IntervalUnit.HOUR that the produced
        /// Trigger will repeat at.
        /// 
        /// 
        /// 
        /// the number of hours at which the trigger should repeat.
        /// the updated CalendarIntervalScheduleBuilder
        /// 
        /// 
        public CalendarIntervalScheduleBuilder WithIntervalInHours(int intervalInHours)
        {
            ValidateInterval(intervalInHours);
            interval = intervalInHours;
            intervalUnit = IntervalUnit.Hour;
            return this;
        }

        /// 
        /// Specify an interval in the IntervalUnit.DAY that the produced
        /// Trigger will repeat at.
        /// 
        /// 
        /// 
        /// the number of days at which the trigger should repeat.
        /// the updated CalendarIntervalScheduleBuilder
        /// 
        /// 
        public CalendarIntervalScheduleBuilder WithIntervalInDays(int intervalInDays)
        {
            ValidateInterval(intervalInDays);
            interval = intervalInDays;
            intervalUnit = IntervalUnit.Day;
            return this;
        }

        /// 
        /// Specify an interval in the IntervalUnit.WEEK that the produced
        /// Trigger will repeat at.
        /// 
        /// 
        /// 
        /// the number of weeks at which the trigger should repeat.
        /// the updated CalendarIntervalScheduleBuilder
        /// 
        /// 
        public CalendarIntervalScheduleBuilder WithIntervalInWeeks(int intervalInWeeks)
        {
            ValidateInterval(intervalInWeeks);
            interval = intervalInWeeks;
            intervalUnit = IntervalUnit.Week;
            return this;
        }

        /// 
        /// Specify an interval in the IntervalUnit.MONTH that the produced
        /// Trigger will repeat at.
        /// 
        /// 
        /// 
        /// the number of months at which the trigger should repeat.
        /// the updated CalendarIntervalScheduleBuilder
        /// 
        /// 
        public CalendarIntervalScheduleBuilder WithIntervalInMonths(int intervalInMonths)
        {
            ValidateInterval(intervalInMonths);
            interval = intervalInMonths;
            intervalUnit = IntervalUnit.Month;
            return this;
        }

        /// 
        /// Specify an interval in the IntervalUnit.YEAR that the produced
        /// Trigger will repeat at.
        /// 
        /// 
        /// 
        /// the number of years at which the trigger should repeat.
        /// the updated CalendarIntervalScheduleBuilder
        /// 
        /// 
        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


评论


亲,登录后才可以留言!