Using Quartz.Net and have a need for the same trigger to have multiple Calendars, whilst this isn’t possible I’m looking for suggestions of how to achieve similar functionality.
For example I want to run the job in X minutes and exlude 9-10am every day but be able to block out other times during the day as required.
The code below works fine but if I want to block out another time interval I can’t see a way of doing it.
ISchedulerFactory schedFact = new StdSchedulerFactory();
sched = schedFact.GetScheduler();
CronCalendar cronCal = new CronCalendar("* * 9 ? * * *");
sched.AddCalendar("testCal", cronCal, true, true);
CronTrigger trigger = new CronTrigger("cronTrigger", null, "0 0/1 * 1/1 * ? *");
trigger.StartTimeUtc = DateTime.UtcNow.AddMinutes(10);
trigger.CalendarName = "testCal";
JobDetail job = new JobDetail("testJob", null, typeof(DumbJob));
sched.ScheduleJob(job, trigger);
sched.start();
Simple test job:
public class DumbJob : IJob
{
public DumbJob()
{
}
public void Execute(JobExecutionContext context)
{
MessageBox.Show("Dumb job is running");
}
}
You can create a chain of calendars. Every calendar can have a base calendar which is also checked when determining whether given time is excluded or included. See CronCalendar’s contructor: