通过配置将日历添加到 Quartz 作业

Add calendar to Quartz job by configuration

我想在节假日将我的一些 Quartz 作业阻塞到 运行,在 the official Quartz page about triggers,我们可以阅读:

Quartz.NET Calendar objects implementing ICalendar interface can be associated with triggers at the time the trigger is stored in the scheduler. Calendars are useful for excluding blocks of time from the the trigger’s firing schedule. For instance, you could create a trigger that fires a job every weekday at 9:30 am, but then add a Calendar that excludes all of the business’s holidays.

我的触发器在配置文件中定义,例如:

<trigger>
  <simple>
    <name>a trigger</name>
    <group>a trigger group</group>
    <description>a trigger description</description>
    <job-name>AJobName</job-name>
    <job-group>a job group</job-group>
    <job-data-map>
      <entry>
        <key>param1</key>
        <value>param1value</value>
      </entry>
    </job-data-map>
    <repeat-count>-1</repeat-count>
    <repeat-interval>300000</repeat-interval>
  </simple>
</trigger>

我可以在不更改 C# 代码的情况下阻止触发器在我的假日日历中的日期触发吗? 如果没有,我是否可以至少在配置中保留触发器定义并在代码中添加日历并将其分配给特定触发器?

所以,这个程序化解决方案不是我要找的:programmatically create trigger and assign calendar

触发器 XML 配置允许您按名称配置日历:

<trigger>
  <simple>
    <calendar-name>myHolidayCalendar<calendar-name>
  </simple>
</trigger>

要使其正常工作,必须在调度程序中注册假日日历:

var calendar = new HolidayCalendar();
calendar.addExcludedDate(DateTime.Today);
scheduler.addCalendar("myHolidayCalendar", calendar, false);