Quartz.Net系列(九):Trigger之DailyTimeIntervalScheduleBuilder详解
1.介绍
中文意义就是每日时间间隔计划生成
2.API讲解
(1)WithInterval、WithIntervalInHours、WithIntervalInMinutes、WithIntervalInSeconds
WithInterval:指定要生成触发器的时间单位和间隔。
WithIntervalInHours:指定要生成触发器的间隔按小时来
WithIntervalInMinutes:指定要生成触发器的间隔按分钟来
WithIntervalInSeconds:指定要生成触发器的间隔按秒来
和前面的SimpleSceduleBuilder、CalendarIntervalScheduleBuilder一样的
(2)OnDaysOfTheWeek、OnMondayThroughFriday、OnSaturdayAndSunday、OnEveryDay
OnDaysOfTheWeek:设置触发器一周中的哪几天
OnMondayThroughFriday:从星期一到星期五
OnSaturdayAndSunday:周六和周日
OnEveryDay:每天
每天10:00到23:10.00的每一分钟执行一次
var trigger = TriggerBuilder.Create().WithDailyTimeIntervalSchedule(
w => w.OnEveryDay() //设置每天
.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(, )) //设置每天开始于几点
.EndingDailyAt(TimeOfDay.HourMinuteAndSecondOfDay(, , )) //设置每日结束于几点
.WithIntervalInMinutes()//间隔分钟
).Build();
一周当中的星期二和星期三每秒执行一次
List<DayOfWeek> dayOfWeeks = new List<DayOfWeek>(); dayOfWeeks.Add(DayOfWeek.Wednesday); dayOfWeeks.Add(DayOfWeek.Tuesday); trigger = TriggerBuilder.Create().WithDailyTimeIntervalSchedule(
w=>w.OnDaysOfTheWeek(dayOfWeeks)//.OnDaysOfTheWeek(new DayOfWeek[2] { DayOfWeek.Wednesday,DayOfWeek.Tuesday})
.WithIntervalInSeconds()
).Build();
源码实现
/// <summary>
/// Set the trigger to fire on the given days of the week.
/// </summary>
/// <param name="onDaysOfWeek">a Set containing the integers representing the days of the week, defined by <see cref="DayOfWeek.Sunday"/> - <see cref="DayOfWeek.Saturday"/>.
/// </param>
/// <returns>the updated DailyTimeIntervalScheduleBuilder</returns>
public DailyTimeIntervalScheduleBuilder OnDaysOfTheWeek(IReadOnlyCollection<DayOfWeek> onDaysOfWeek)
{
if (onDaysOfWeek == null || onDaysOfWeek.Count == )
{
throw new ArgumentException("Days of week must be an non-empty set.");
} foreach (DayOfWeek day in onDaysOfWeek)
{
if (!AllDaysOfTheWeek.Contains(day))
{
throw new ArgumentException("Invalid value for day of week: " + day);
}
} daysOfWeek = new HashSet<DayOfWeek>(onDaysOfWeek);
return this;
} /// <summary>
/// Set the trigger to fire on the given days of the week.
/// </summary>
/// <param name="onDaysOfWeek">a variable length list of week days representing the days of the week</param>
/// <returns>the updated DailyTimeIntervalScheduleBuilder</returns>
public DailyTimeIntervalScheduleBuilder OnDaysOfTheWeek(params DayOfWeek[] onDaysOfWeek)
{
return OnDaysOfTheWeek((IReadOnlyCollection<DayOfWeek>) onDaysOfWeek);
} /// <summary>
/// Set the trigger to fire on the days from Monday through Friday.
/// </summary>
/// <returns>the updated DailyTimeIntervalScheduleBuilder</returns>
public DailyTimeIntervalScheduleBuilder OnMondayThroughFriday()
{
daysOfWeek = new HashSet<DayOfWeek>(MondayThroughFriday);
return this;
} /// <summary>
/// Set the trigger to fire on the days Saturday and Sunday.
/// </summary>
/// <returns>the updated DailyTimeIntervalScheduleBuilder</returns>
public DailyTimeIntervalScheduleBuilder OnSaturdayAndSunday()
{
daysOfWeek = new HashSet<DayOfWeek>(SaturdayAndSunday);
return this;
} /// <summary>
/// Set the trigger to fire on all days of the week.
/// </summary>
/// <returns>the updated DailyTimeIntervalScheduleBuilder</returns>
public DailyTimeIntervalScheduleBuilder OnEveryDay()
{
daysOfWeek = new HashSet<DayOfWeek>(AllDaysOfTheWeek);
return this;
}
(3)StartingDailyAt、EndingDailyAt
StartingDailyAt:开始时间于
EndingDailyAt:结束时间于
源码实现
/// <summary>
/// The TimeOfDay for this trigger to start firing each day.
/// </summary>
/// <param name="timeOfDayUtc"></param>
/// <returns>the updated DailyTimeIntervalScheduleBuilder</returns>
public DailyTimeIntervalScheduleBuilder StartingDailyAt(TimeOfDay timeOfDayUtc)
{
startTimeOfDayUtc = timeOfDayUtc ?? throw new ArgumentException("Start time of day cannot be null!");
return this;
} /// <summary>
/// The TimeOfDay for this trigger to end firing each day.
/// </summary>
/// <param name="timeOfDayUtc"></param>
/// <returns>the updated DailyTimeIntervalScheduleBuilder</returns>
public DailyTimeIntervalScheduleBuilder EndingDailyAt(TimeOfDay timeOfDayUtc)
{
endTimeOfDayUtc = timeOfDayUtc;
return this;
}
(4)EndingDailyAfterCount
EndingDailyAfterCount:使用count、interval和StarTimeOfDay计算并设置EndTimeOfDay。
源码实现
/// <summary>
/// Calculate and set the EndTimeOfDay using count, interval and StarTimeOfDay. This means
/// that these must be set before this method is call.
/// </summary>
/// <param name="count"></param>
/// <returns>the updated DailyTimeIntervalScheduleBuilder</returns>
public DailyTimeIntervalScheduleBuilder EndingDailyAfterCount(int count)
{
if (count <= )
{
throw new ArgumentException("Ending daily after count must be a positive number!");
} if (startTimeOfDayUtc == null)
{
throw new ArgumentException("You must set the StartDailyAt() before calling this EndingDailyAfterCount()!");
} DateTimeOffset today = SystemTime.UtcNow();
DateTimeOffset startTimeOfDayDate = startTimeOfDayUtc.GetTimeOfDayForDate(today).Value;
DateTimeOffset maxEndTimeOfDayDate = TimeOfDay.HourMinuteAndSecondOfDay(, , ).GetTimeOfDayForDate(today).Value; //apply proper offsets according to timezone
TimeZoneInfo targetTimeZone = timeZone ?? TimeZoneInfo.Local;
startTimeOfDayDate = new DateTimeOffset(startTimeOfDayDate.DateTime, TimeZoneUtil.GetUtcOffset(startTimeOfDayDate.DateTime, targetTimeZone));
maxEndTimeOfDayDate = new DateTimeOffset(maxEndTimeOfDayDate.DateTime, TimeZoneUtil.GetUtcOffset(maxEndTimeOfDayDate.DateTime, targetTimeZone)); TimeSpan remainingMillisInDay = maxEndTimeOfDayDate - startTimeOfDayDate;
TimeSpan intervalInMillis;
if (intervalUnit == IntervalUnit.Second)
{
intervalInMillis = TimeSpan.FromSeconds(interval);
}
else if (intervalUnit == IntervalUnit.Minute)
{
intervalInMillis = TimeSpan.FromMinutes(interval);
}
else if (intervalUnit == IntervalUnit.Hour)
{
intervalInMillis = TimeSpan.FromHours(interval);
}
else
{
throw new ArgumentException("The IntervalUnit: " + intervalUnit + " is invalid for this trigger.");
} if (remainingMillisInDay < intervalInMillis)
{
throw new ArgumentException("The startTimeOfDay is too late with given Interval and IntervalUnit values.");
} long maxNumOfCount = remainingMillisInDay.Ticks / intervalInMillis.Ticks;
if (count > maxNumOfCount)
{
throw new ArgumentException("The given count " + count + " is too large! The max you can set is " + maxNumOfCount);
} TimeSpan incrementInMillis = TimeSpan.FromTicks((count - ) * intervalInMillis.Ticks);
DateTimeOffset endTimeOfDayDate = startTimeOfDayDate.Add(incrementInMillis); if (endTimeOfDayDate > maxEndTimeOfDayDate)
{
throw new ArgumentException("The given count " + count + " is too large! The max you can set is " + maxNumOfCount);
} DateTime cal = SystemTime.UtcNow().Date;
cal = cal.Add(endTimeOfDayDate.TimeOfDay);
endTimeOfDayUtc = TimeOfDay.HourMinuteAndSecondOfDay(cal.Hour, cal.Minute, cal.Second);
return this;
}
Quartz.Net系列(九):Trigger之DailyTimeIntervalScheduleBuilder详解的更多相关文章
- SpringBoot系列(十二)过滤器配置详解
SpringBoot(十二)过滤器详解 往期精彩推荐 SpringBoot系列(一)idea新建Springboot项目 SpringBoot系列(二)入门知识 springBoot系列(三)配置文件 ...
- 深入浅出Mybatis系列(四)---配置详解之typeAliases别名(mybatis源码篇)
上篇文章<深入浅出Mybatis系列(三)---配置详解之properties与environments(mybatis源码篇)> 介绍了properties与environments, ...
- Android Studio系列教程五--Gradle命令详解与导入第三方包
Android Studio系列教程五--Gradle命令详解与导入第三方包 2015 年 01 月 05 日 DevTools 本文为个人原创,欢迎转载,但请务必在明显位置注明出处!http://s ...
- Android 颜色渲染(九) PorterDuff及Xfermode详解
版权声明:本文为博主原创文章,未经博主允许不得转载. Android 颜色渲染(九) PorterDuff及Xfermode详解 之前已经讲过了除ComposeShader之外Shader的全部子类 ...
- 构建安全的Xml Web Service系列之wse之错误代码详解
原文:构建安全的Xml Web Service系列之wse之错误代码详解 WSE3.0现在还没有中文版的可以下载,使用英文版的过程中,难免会遇到各种各样的错误,而面对一堆毫无头绪的错误异常,常常会感到 ...
- [js高手之路] es6系列教程 - 对象功能扩展详解
第一:字面量对象的方法,支持缩写形式 //es6之前,这么写 var User = { name : 'ghostwu', showName : function(){ return this.nam ...
- “全栈2019”Java多线程第十九章:死锁详解
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java多 ...
- “全栈2019”Java异常第十九章:RuntimeException详解
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java异 ...
- “全栈2019”Java第二十九章:数组详解(中篇)
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...
随机推荐
- Hello, CTF
0x01 拿到题目后查壳,发现什么也没有,32位vc++ 0x02 放到IDA里,F5反编译,得到下图 很容易我们就看到了比较的函数,以及出现wrong和success的字符串,所以接下来就是仔细分析 ...
- 50个SQL语句(MySQL版) 问题五
--------------------------表结构-------------------------- student(StuId,StuName,StuAge,StuSex) 学生表 tea ...
- Rocket - decode - 最小项与最大项
https://mp.weixin.qq.com/s/XrBh9Kapj01HdvBi5MkbgA 介绍布尔代数最小项与最大项相关概念,以及Term类的实现. 参考链接: https:// ...
- Java实现第八届蓝桥杯国赛 数字划分
标题:数字划分 w星球的长老交给小明一个任务: 1,2,3-16 这16个数字分为两组. 要求: 这两组数字的和相同, 并且,两组数字的平方和也相同, 并且,两组数字的立方和也相同. 请你利用计算机的 ...
- 第五届蓝桥杯JavaA组国(决)赛真题
解题代码部分来自网友,如果有不对的地方,欢迎各位大佬评论 题目1.海盗分金币 有5个海盗,相约进行一次帆船比赛. 比赛中天气发生突变,他们被冲散了. 恰巧,他们都先后经过途中的一个无名的荒岛,并且每个 ...
- Java实现第十届蓝桥杯人物相关性分析
试题 H: 人物相关性分析 时间限制: 1.0s 内存限制: 512.0MB 本题总分:20 分 [问题描述] 小明正在分析一本小说中的人物相关性.他想知道在小说中 Alice 和 Bob 有多少次同 ...
- 用户管理命令-passwd
passwd可以给用户设置密码或者修改密码,超级用户可以修改任何用户的密码,而且可以不遵守密码的复杂性原则,普通用户只能修改自己的密码,必须遵守密码的复杂性原则 passwd [选项] 用户名 常用选 ...
- Python面试常用的高级用法,怎么动态创建类?
本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是Python专题的第16篇文章,今天我们来聊聊Python当中的元类. 元类是Python当中的高级用法,如果你之前从来没见过这个术语 ...
- jenkins+svn 自动化上线
一.环境: [root@bimvm01 ~]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) [root@bimvm01 ~ ...
- [computer graphics]世界坐标系->相机坐标系详细推导
基变换 理论部分 在n维的线性空间中,任意n个线性无关的向量都可以作为线性空间的基,即空间基不唯一.对于不同的基,同一个向量的坐标一般是不同的.因为在计算机图形学中,主要研究三维的空间,所以可以简化问 ...