I've started using Quartz.NET recently, and so far, it's been really helpful. Now, I'm trying to use it to create a job that runs once a month using a NthIncludedDayTrigger (I want to use the NthIncludedDayTrigger as eventually I will be specifying a calendar to exclude weekends/holidays).
To familiarise myself with the code, I've set up a simple console application to create an NthIncludedDayTrigger where the first fire time will be 15 seconds from now:
static void Main(string[] args)
{
IScheduler scheduler = StdSchedulerFactory.DefaultScheduler;
scheduler.Start();
var jobDetail = new JobDetail("Job name", "Group name", typeof(SomeIJobImplementation));
var trigger = new NthIncludedDayTrigger();
trigger.Name = "Trigger name";
trigger.MisfireInstruction = MisfireInstruction.NthIncludedDayTrigger.DoNothing;
trigger.IntervalType = NthIncludedDayTrigger.IntervalTypeMonthly;
//I'm using the following while experimenting with the code (AddHour(1) to account for BST):
trigger.FireAtTime = DateTime.UtcNow.AddHours(1).AddSeconds(15).ToString("HH:mm:ss");
//I'm using the following while experimenting with the code:
trigger.N = DateTime.Today.Day;
Console.WriteLine("Started, press any key to stop ...");
Console.ReadKey();
scheduler.Shutdown(false);
}
...
public class SomeIJobImplementation : IJob
{
public void Execute(JobExecutionContext context)
{
Logger.Write(String.Format(
"Job executed called at {0}",
DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss")), null, 1,
TraceEventType.Information);
}
}
Running this results in the job being executed multiple times (approximately once per second) for one minute. I'm using an ADO.NET job store and can see in my database that QRTZ_TRIGGERS.NEXT_FIRE_TIME is set to the last executed time, i.e. doesn't seem to be scheduled to run again.
I expected the above code to run the job once (after about 15 seconds), then schedule the job to run again in one months time.
Perphaps the issue is just with the way I'm using Quartz.NET whilst I've been experimenting or, maybe, my expectations are wrong? Either way, I would be most grateful for any help/suggestions to explain the behaviour I've observed, and what I need to change to get the behaviour I want.