I am trying to get Quartz.net scheduler to work, but I don't know why it is not firing for jobs scheduled at a future date. I have tested with a cron trigger that fires every minute and it works (job and all), so I know it isn't a problem with my job code.
Things I have tried:
- Making the ISchedulerFactory a global static variable
- Making the IScheduler a global static variable
- I have added an email notification to the end of the Application_Start so I know when it is firing
- Every time I make changes to the scheduler code I restart the app and it fires my notification email, so I know it was restarted.
I am running this program on a shared hosting environment (not sure if that would have any effect on it). My guess (and this is only a guess) is something is being garbage collected, but I'm not sure what and why.
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
// construct a scheduler factory
ISchedulerFactory schedFact = new StdSchedulerFactory();
// get a scheduler
IScheduler sched = schedFact.GetScheduler();
sched.Start();
// construct job info
JobDetail jobDetail = new JobDetail("myJob", null, typeof(Recorder));
jobDetail.JobDataMap["domain"] = "www.mydomain.com";
jobDetail.JobDataMap["userId"] = "2";
// Create trigger (everything is in UTC!!!)
CronTrigger cronTrigger = new CronTrigger("Schedule");
cronTrigger.StartTimeUtc = TriggerUtils.GetEvenSecondDate(DateTime.UtcNow);
cronTrigger.TimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"); // run in pacific timezone
cronTrigger.CronExpressionString = "0 30 13 ? * MON-FRI *";
sched.ScheduleJob(jobDetail, cronTrigger);
}