Quartz.Net系列(七):Trigger之SimpleScheduleBuilder详解
2020-06-20 14:58
621 查看
所有方法图
SimpleScheduleBuilder方法
RepeatForever:指定触发器将无限期重复。
WithRepeatCount:指定重复次数
var trigger = TriggerBuilder.Create().WithSimpleSchedule(s=>s.WithIntervalInSeconds(1).RepeatForever()).Build();
var trigger = TriggerBuilder.Create().WithSimpleSchedule(s=>s.WithIntervalInSeconds(1) .WithRepeatCount(10)).Build();
注:底层实现是repeatCount+1,也就是总共执行repeatCount+1次
/// <summary> /// Specify a the number of time the trigger will repeat - total number of /// firings will be this number + 1. /// </summary> /// <remarks> /// </remarks> /// <param name="repeatCount">the number of seconds at which the trigger should repeat.</param> /// <returns>the updated SimpleScheduleBuilder</returns> /// <seealso cref="ISimpleTrigger.RepeatCount" /> /// <seealso cref="RepeatForever" /> public SimpleScheduleBuilder WithRepeatCount(int repeatCount) { this.repeatCount = repeatCount; return this; }
WithInterval:以毫秒为单位指定重复间隔,由于是TimeSpan也可以指定时分秒
WithIntervalInHours:以小时为单位指定重复间隔
WithIntervalInMinutes:以分钟单位指定重复间隔
WithIntervalInSeconds:以秒为单位指定重复间隔
var trigger = TriggerBuilder.Create().WithSimpleSchedule(s=>s .WithIntervalInSeconds(1) .WithInterval(TimeSpan.FromDays(1)) .WithIntervalInMinutes(1) .WithIntervalInHours(1) .WithRepeatCount(5)) .Build();
注:底层都是通过WithInterval实现的
/// <summary> /// Specify a repeat interval in milliseconds. /// </summary> /// <remarks> /// </remarks> /// <param name="timeSpan">the time span at which the trigger should repeat.</param> /// <returns>the updated SimpleScheduleBuilder</returns> /// <seealso cref="ISimpleTrigger.RepeatInterval" /> /// <seealso cref="WithRepeatCount(int)" /> public SimpleScheduleBuilder WithInterval(TimeSpan timeSpan) { interval = timeSpan; return this; } /// <summary> /// Specify a repeat interval in seconds. /// </summary> /// <remarks> /// </remarks> /// <param name="seconds">the time span at which the trigger should repeat.</param> /// <returns>the updated SimpleScheduleBuilder</returns> /// <seealso cref="ISimpleTrigger.RepeatInterval" /> /// <seealso cref="WithRepeatCount(int)" /> public SimpleScheduleBuilder WithIntervalInSeconds(int seconds) { return WithInterval(TimeSpan.FromSeconds(seconds)); }
静态方法:
RepeatMinutelyForever
RepeatMinutelyForTotalCount
RepeatSecondlyForever
RepeatSecondlyForTotalCount
RepeatHourlyForever
RepeatHourlyForTotalCount
var trigger = TriggerBuilder.Create().WithSchedule(SimpleScheduleBuilder.RepeatSecondlyForTotalCount(2)).Build();
/// <summary> /// Create a SimpleScheduleBuilder set to repeat forever with a 1 minute interval. /// </summary> /// <remarks> /// </remarks> /// <returns>the new SimpleScheduleBuilder</returns> public static SimpleScheduleBuilder RepeatMinutelyForever() { SimpleScheduleBuilder sb = Create() .WithInterval(TimeSpan.FromMinutes(1)) .RepeatForever(); return sb; } /// <summary> /// Create a SimpleScheduleBuilder set to repeat forever with an interval /// of the given number of minutes. /// </summary> /// <remarks> /// </remarks> /// <returns>the new SimpleScheduleBuilder</returns> public static SimpleScheduleBuilder RepeatMinutelyForever(int minutes) { SimpleScheduleBuilder sb = Create() .WithInterval(TimeSpan.FromMinutes(minutes)) .RepeatForever(); return sb; } /// <summary> /// Create a SimpleScheduleBuilder set to repeat forever with a 1 second interval. /// </summary> /// <remarks> /// </remarks> /// <returns>the new SimpleScheduleBuilder</returns> public static SimpleScheduleBuilder RepeatSecondlyForever() { SimpleScheduleBuilder sb = Create() .WithInterval(TimeSpan.FromSeconds(1)) .RepeatForever(); return sb; } /// <summary> /// Create a SimpleScheduleBuilder set to repeat forever with an interval /// of the given number of seconds. /// </summary> /// <remarks> /// </remarks> /// <returns>the new SimpleScheduleBuilder</returns> public static SimpleScheduleBuilder RepeatSecondlyForever(int seconds) { SimpleScheduleBuilder sb = Create() .WithInterval(TimeSpan.FromSeconds(seconds)) .RepeatForever(); return sb; } /// <summary> /// Create a SimpleScheduleBuilder set to repeat forever with a 1 hour interval. /// </summary> /// <remarks> /// </remarks> /// <returns>the new SimpleScheduleBuilder</returns> public static SimpleScheduleBuilder RepeatHourlyForever() { SimpleScheduleBuilder sb = Create() .WithInterval(TimeSpan.FromHours(1)) .RepeatForever(); return sb; } /// <summary> /// Create a SimpleScheduleBuilder set to repeat forever with an interval /// of the given number of hours. /// </summary> /// <remarks> /// </remarks> /// <returns>the new SimpleScheduleBuilder</returns> public static SimpleScheduleBuilder RepeatHourlyForever(int hours) { SimpleScheduleBuilder sb = Create() .WithInterval(TimeSpan.FromHours(hours)) .RepeatForever(); return sb; } /// <summary> /// Create a SimpleScheduleBuilder set to repeat the given number /// of times - 1 with a 1 minute interval. /// </summary> /// <remarks> /// <para>Note: Total count = 1 (at start time) + repeat count</para> /// </remarks> /// <returns>the new SimpleScheduleBuilder</returns> public static SimpleScheduleBuilder RepeatMinutelyForTotalCount(int count) { if (count < 1) { throw new ArgumentException("Total count of firings must be at least one! Given count: " + count); } SimpleScheduleBuilder sb = Create() .WithInterval(TimeSpan.FromMinutes(1)) .WithRepeatCount(count - 1); return sb; } /// <summary> /// Create a SimpleScheduleBuilder set to repeat the given number /// of times - 1 with an interval of the given number of minutes. /// </summary> /// <remarks> /// <para>Note: Total count = 1 (at start time) + repeat count</para> /// </remarks> /// <returns>the new SimpleScheduleBuilder</returns> public static SimpleScheduleBuilder RepeatMinutelyForTotalCount(int count, int minutes) { if (count < 1) { throw new ArgumentException("Total count of firings must be at least one! Given count: " + count); } SimpleScheduleBuilder sb = Create() .WithInterval(TimeSpan.FromMinutes(minutes)) .WithRepeatCount(count - 1); return sb; } /// <summary> /// Create a SimpleScheduleBuilder set to repeat the given number /// of times - 1 with a 1 second interval. /// </summary> /// <remarks> /// <para>Note: Total count = 1 (at start time) + repeat count</para> /// </remarks> /// <returns>the new SimpleScheduleBuilder</returns> public static SimpleScheduleBuilder RepeatSecondlyForTotalCount(int count) { if (count < 1) { throw new ArgumentException("Total count of firings must be at least one! Given count: " + count); } SimpleScheduleBuilder sb = Create() .WithInterval(TimeSpan.FromSeconds(1)) .WithRepeatCount(count - 1); return sb; } /// <summary> /// Create a SimpleScheduleBuilder set to repeat the given number /// of times - 1 with an interval of the given number of seconds. /// </summary> /// <remarks> /// <para>Note: Total count = 1 (at start time) + repeat count</para> /// </remarks> /// <returns>the new SimpleScheduleBuilder</returns> public static SimpleScheduleBuilder RepeatSecondlyForTotalCount(int count, int seconds) { if (count < 1) { throw new ArgumentException("Total count of firings must be at least one! Given count: " + count); } SimpleScheduleBuilder sb = Create() .WithInterval(TimeSpan.FromSeconds(seconds)) .WithRepeatCount(count - 1); return sb; } /// <summary> /// Create a SimpleScheduleBuilder set to repeat the given number /// of times - 1 with a 1 hour interval. /// </summary> /// <remarks> /// <para>Note: Total count = 1 (at start time) + repeat count</para> /// </remarks> /// <returns>the new SimpleScheduleBuilder</returns> public static SimpleScheduleBuilder RepeatHourlyForTotalCount(int count) { if (count < 1) { throw new ArgumentException("Total count of firings must be at least one! Given count: " + count); } SimpleScheduleBuilder sb = Create() .WithInterval(TimeSpan.FromHours(1)) .WithRepeatCount(count - 1); return sb; } /// <summary> /// Create a SimpleScheduleBuilder set to repeat the given number /// of times - 1 with an interval of the given number of hours. /// </summary> /// <remarks> /// <para>Note: Total count = 1 (at start time) + repeat count</para> /// </remarks> /// <returns>the new SimpleScheduleBuilder</returns> public static SimpleScheduleBuilder RepeatHourlyForTotalCount(int count, int hours) { if (count < 1) { throw new ArgumentException("Total count of firings must be at least one! Given count: " + count); } SimpleScheduleBuilder sb = Create() .WithInterval(TimeSpan.FromHours(hours)) .WithRepeatCount(count - 1); return sb; }
相关文章推荐
- Quartz.Net系列(九):Trigger之DailyTimeIntervalScheduleBuilder详解
- Quartz.Net系列(八):Trigger之CalendarIntervalScheduleBuilder详解
- Quartz入门实例2-根据SimpleScheduleBuilder配置不同的SimpleTrigger触发器
- 第二十三节: EF性能篇(三)之基于开源组件 Z.EntityFrameWork.Plus.EF6解决EF性能问题 第四节:一些指令总结 定时调度系列之Quartz.Net详解 第十七节:易混淆的概念(静态和非静态、拆箱和装箱) 那些年我们一起追逐的多线程(Thread、ThreadPool、委托异步调用、Task/TaskFactory、Parallerl、async和await)
- Quartz.NET作业调度框架详解
- Java定时任务调度工具详解之Quartz篇(中级)一:浅谈JobExecutionContext&JobDatai&浅谈Trigger
- 作业调度框架Quartz 触发器(SimpleTrigger&CronTrigger )配置说明
- 【学习笔记】Spring-Quartz-SimpleTriggerBean时间格式
- Quartz 触发器(SimpleTrigger&CronTrigger )配置说明 & cronExpression表达式
- 任务调度框架Quartz(二) 使用job、trigger、schedule调用定时任务
- Spring+Quartz整合(2)之SimpleTrigger
- Quartz的DateBuilder详解
- [置顶] Quartz的DateBuilder详解
- Quartz.NET作业调度框架详解
- 对象类亮剑.NET的系列文章之.NET详解(开端)
- Quartz.net官方开发指南 第七课 : TriggerListeners和JobListeners
- Quartz.net配置文件实例及cron表达式详解
- 【解决】SSH问题(三)java.lang.ClassNotFoundException: org.quartz.impl.triggers.SimpleTriggerImpl
- Quartz 触发器(SimpleTrigger&CronTrigger )配置说明 & cronExpression表达式
- Spring任务调度实战之Quartz Simple Trigger