Reputation: 32291
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:
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);
}
Upvotes: 1
Views: 484
Reputation: 3401
ASP.NET process can be shut down by IIS if no requests are coming in, so none of this code would be fired.
This is the reason why web-apps are not a good source of service-like (always running) behavior.
I've seen this implemented in a web-app with a page/web service which gets pinged via cURL
tool from the outside.
If you're interested in debugging this further, add some notification in Application_End
just to make sure that the process is actually shut down before the timer fires your scheduled job.
Upvotes: 2