Quartz.Net系列:Trigger之CalendarIntervalScheduleBuilder详解
Posted vic-tory
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Quartz.Net系列:Trigger之CalendarIntervalScheduleBuilder详解相关的知识,希望对你有一定的参考价值。
所有方法图
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详解的主要内容,如果未能解决你的问题,请参考以下文章
.Net Quartz.NET Trigger 触发器使用以及重入问题