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");
}
}
I managed to find the solution to implement multi calendar and find the link : Quartz.Net multple calendars Marko Lahma give the solution to create calendar chain with BaseCaleandar.
I tested and find there is some bug in calendar chain.
I just change some code in
Quartz.Examples.2010.Example8
.Add a WeeklyCalendar to the AnnualCalendar:
Add two holidays into AnuualCalendar for next two days:
Attach the AnnualCalendar to a SimpleTrigger with IntervalInHourse for 72h/96h/120h and fire in 1/21.
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: