动态的排除一些触发器的时间。

DailyCalendar-天日历

定义:

This implementation of the Calendar excludes (or includes - see below) a specified time range each day.

排除 天  内的一个时间段。或者叫做 在天上做减法操作。

 

private async void button8_Click_1(object sender, EventArgs e)
{
ISchedulerFactory sf = new StdSchedulerFactory();
var schdeler = await sf.GetScheduler();
await schedu.Start();
IJobDetail job = JobBuilder.Create<MyJob5>().WithDescription("JOB5").StoreDurably(true).Build(); //某一天的时间段上做减法操作。
DailyCalendar dailyCa = new DailyCalendar(DateBuilder.DateOf(, , ).DateTime, DateBuilder.DateOf(, , ).DateTime);
await schdeler.AddCalendar("ceshica", dailyCa,true,true); //ModifiedByCalendar 减去时间段
ITrigger trigger = TriggerBuilder.Create().WithCronSchedule("* * * * * ?").ModifiedByCalendar("ceshica").Build(); await schedu.ScheduleJob(job, trigger);
}
WeeklyCalendar-周日历

定义:

This implementation of the Calendar excludes a set of days of the week. You may use it to exclude weekends for example. But you may define any day of the week. By default it excludes Saturday and Sunday.

该日历的实现不包括一组星期的天数。你可以用它来排除周末。但是你可以定义一周中的任何一天。默认情况下,它不包括周六和周日。

private async void button9_Click(object sender, EventArgs e)
{
ISchedulerFactory sf = new StdSchedulerFactory();
var schdeler = await sf.GetScheduler();
await schedu.Start();
IJobDetail job = JobBuilder.Create<MyJob5>().WithDescription("JOB5").StoreDurably(true).Build(); //一周内 某些天数做减法。 默认周六周日是排除的。
WeeklyCalendar weekCa = new WeeklyCalendar(); weekCa.SetDayExcluded(DayOfWeek.Friday, true); await schdeler.AddCalendar("ceshica", weekCa, true, true); //ModifiedByCalendar 减去周内的 几天
ITrigger trigger = TriggerBuilder.Create().WithCronSchedule("* * * * * ?").ModifiedByCalendar("ceshica").Build(); await schedu.ScheduleJob(job, trigger);
}
HolidayCalendar-假期日历

定义:

This implementation of the Calendar stores a list of holidays (full days that are excluded from scheduling).

该日历的实现存储了一个假日列表(被排除在调度之外的完整天数)。

适合用在某一天  假期等,或者当年的某一天不能执行。

private async void button10_Click(object sender, EventArgs e)
{
ISchedulerFactory sf = new StdSchedulerFactory();
var schdeler = await sf.GetScheduler();
await schedu.Start();
IJobDetail job = JobBuilder.Create<MyJob5>().WithDescription("JOB5").StoreDurably(true).Build(); //制定某一天不能执行。 这个更加倾向于 holiday 假期。一般工作通过工作日历表中找出所有的假期,然后放入holidaycalendar。
HolidayCalendar holidayCa = new HolidayCalendar();
holidayCa.AddExcludedDate(DateTime.Now);//排除今天。
//holidayCa.RemoveExcludedDate(DateTime.Now);//后期可以动态处理
await schdeler.AddCalendar("ceshica", holidayCa, true, true); //ModifiedByCalendar 减去周内的 几天
ITrigger trigger = TriggerBuilder.Create().WithCronSchedule("* * * * * ?").ModifiedByCalendar("ceshica").Build(); await schedu.ScheduleJob(job, trigger);
}
MonthlyCalendar-月日历

定义:

This implementation of the Calendar excludes a set of days of the month. You may use it to exclude every 1. of each month for example. But you may define any day of a month.

这个日历的实现不包括一个月的天数。你可以用它来排除每个月一号。但是你也可以定义一个月的任何一天。

private async void button11_Click(object sender, EventArgs e)
{
ISchedulerFactory sf = new StdSchedulerFactory();
var schdeler = await sf.GetScheduler();
await schedu.Start();
IJobDetail job = JobBuilder.Create<MyJob5>().WithDescription("JOB5").StoreDurably(true).Build(); MonthlyCalendar monthlyCa = new MonthlyCalendar();
//月份中的某一天不能被执行。
monthlyCa.SetDayExcluded(, true); await schdeler.AddCalendar("ceshica", monthlyCa, true, true); //ModifiedByCalendar 减去周内的 几天
ITrigger trigger = TriggerBuilder.Create().WithCronSchedule("* * * * * ?").ModifiedByCalendar("ceshica").Build(); await schedu.ScheduleJob(job, trigger); }
AnnualCalendar-年日历

定义:

This implementation of the Calendar excludes a set of days of the year. You may use it to exclude bank holidays which are on the same date every year.

该日历的实现不包括一组年份。你可以用它来排除每年同一日期的银行假日。  适合每年的每一天不能执行  比如说国庆节  不干活。

private async void button12_Click(object sender, EventArgs e)
{
ISchedulerFactory sf = new StdSchedulerFactory();
var schdeler = await sf.GetScheduler();
await schedu.Start();
IJobDetail job = JobBuilder.Create<MyJob5>().WithDescription("JOB5").StoreDurably(true).Build() AnnualCalendar annualCa = new AnnualCalendar();
//每年这几天不执行
annualCa.SetDayExcluded(new DateTime(, , ), true);
annualCa.SetDayExcluded(new DateTime(, , ), true);
annualCa.SetDayExcluded(new DateTime(, , ), true);
annualCa.SetDayExcluded(new DateTime(, ,), true);
annualCa.SetDayExcluded(new DateTime(, , ), true);
annualCa.SetDayExcluded(new DateTime(, , ), true);
annualCa.SetDayExcluded(new DateTime(, , ), true); annualCa.SetDayExcluded(new DateTime(, , ), true); await schdeler.AddCalendar("ceshica", annualCa, true, true); //ModifiedByCalendar
ITrigger trigger = TriggerBuilder.Create().WithCronSchedule("* * * * * ?").ModifiedByCalendar("ceshica").Build(); await schedu.ScheduleJob(job, trigger);
}
CronCalendar-Cron日历

定义:

This implementation of the Calendar excludes the set of times expressed by a given CronExpression.

该日历的实现不包括给定的CronExpression所表示的时间集合。  也就是排除cron时间。

private async void button13_Click(object sender, EventArgs e)
{
ISchedulerFactory sf = new StdSchedulerFactory();
var schdeler = await sf.GetScheduler();
await schedu.Start();
IJobDetail job = JobBuilder.Create<MyJob5>().WithDescription("JOB5").StoreDurably(true).Build(); CronCalendar cronCa = new CronCalendar("1,5,10,15,20,25,30,35,40,45,50,55 * * * * ?"); await schdeler.AddCalendar("ceshica", cronCa, true, true); //ModifiedByCalendar
ITrigger trigger = TriggerBuilder.Create().WithCronSchedule("* * * * * ?").ModifiedByCalendar("ceshica").Build(); await schedu.ScheduleJob(job, trigger);
}

Quartz.Net—Calendar的更多相关文章

  1. Quartz Scheduler Calendar日历的使用

    Quartz Calendar 日历的使用 quartz引擎为我们提供了日历的功能,让我们可以自己定义一个时间段,可以控制触发器在这个时间段内触发或者不触发,比如可以设置节假日,工作时间早8晚5等等. ...

  2. Quartz任务调度基本使用

    转自:http://www.cnblogs.com/bingoidea/archive/2009/08/05/1539656.html 上一篇:定时器的实现.Java定时器Timer和Quartz介绍 ...

  3. Quartz 入门详解

    Quartz是OpenSymphony开源组织在Job scheduling领域又一个开源项目,它可以与J2EE与J2SE应用程序相结合也可以单独使用.Quartz可以用来创建简单或为运行十个,百个, ...

  4. 使用Quartz.NET进行任务调度管理

    1.Quartz.NET 介绍 Quartz.NET是一个开源的作业调度框架,是OpenSymphony 的 Quartz API的.NET移植,它用C#写成,可用于winform和asp.net应用 ...

  5. Quartz.NET开源作业调度框架系列(三):IJobExecutionContext 参数传递

    前面写了关于Quartz.NET开源作业调度框架的入门和Cron Trigger , 这次继续这个系列, 这次想讨论一下Quartz.NET中的Job如何通过执行上下文(Execution Conte ...

  6. Quartz集群

    为什么选择Quartz: 1)资历够老,创立于1998年,比struts1还早,但是一直在更新(27 April 2012: Quartz 2.1.5 Released),文档齐全. 2)完全由Jav ...

  7. Quartz任务调度快速入门(转)

    转自http://www.blogjava.net/baoyaer/articles/155645.html 概述 了解Quartz体系结构 Quartz对任务调度的领域问题进行了高度的抽象,提出了调 ...

  8. Quartz将Job保存在数据库中所需表的说明

    http://blog.iqbon.com/doc/364.html   (将Quartz持久化到数据库的做法)   QRTZ_CALENDARS 以 Blob 类型存储 Quartz 的 Calen ...

  9. 用Quartz进行作业调度(转)

    概述 各种企业应用几乎都会碰到任务调度的需求,就拿论坛来说:每隔半个小时生成精华文章的RSS文件,每天凌晨统计论坛用户的积分排名,每隔30分钟执行锁定用户解锁任务. 对于一个典型的MIS系统来说,在每 ...

随机推荐

  1. Redis企业实战的几个坑

    一.前言 小伙伴们对Redis应该不陌生,Redis是系统必备的分布式缓存中间件,主要用来解决高并发下分担DB资源的负载,从而提升系统吞吐量. Redis支持多种数据类型,String(字符串).li ...

  2. 性能测试学习第八天-----linux环境整合篇

  3. arts打卡13周

    算法: 报数序列是一个整数序列,按照其中的整数的顺序进行报数,得到下一个数.其前五项如下: 1. 12. 113. 214. 12115. 1112211 被读作  "one 1" ...

  4. Python常量类

    class _const: class ConstError(TypeError): pass class ConstCaseError(ConstError): pass def __setattr ...

  5. Git的使用(1) —— 版本库

    1. 简介 Git作为一个分布式版本控制系统,其优点是不需要一直连接远端版本库就可以使用. 故其为实现分布版本控制专门设计了一整套的存储区间和语句,用来实现. (1) 本地版本库:建立在本机磁盘上的文 ...

  6. ubuntu之路——day8.2 深度学习优化算法之指数加权平均与偏差修正,以及基于指数加权移动平均法的动量梯度下降法

    首先感谢吴恩达老师的免费公开课,以下图片均来自于Andrew Ng的公开课 指数加权平均法 在统计学中被称为指数加权移动平均法,来看下面一个例子: 这是伦敦在一些天数中的气温分布图 Vt = βVt- ...

  7. 解决 screen 连接不上,提示“There is no screen to be resumed matching 18352.” 的问题

    当你挂起screen,下次想重新连上screen时,有时会出现screen session的状态为Attached但是却连不上的情况,比如我想重新进入session id 为18352的screen, ...

  8. Java ArrayList,LinkedList使用

    1.ArrayList底层采用数组实现,当使用不带参数的构造方法生成ArrayList对象时,实际上回在底层生成一个长度为10的Object类型数组. 2.如果增加的元素个数超过10个,那么Array ...

  9. CentOS 安装抓包工具wireshark-tshark抓包工具

    原文出处:razeen -> https://razeen.me/post/how-to-install-tshark-on-centos.html 准备在服务器上用tshark抓包,分析一下数 ...

  10. openresty开发系列25--openresty中使用json模块

    openresty开发系列25--openresty中使用json模块 web开发过程中,经常用的数据结构为json,openresty中封装了json模块,我们看如何使用 一)如何引入cjson模块 ...