Question

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:

  1. Making the ISchedulerFactory a global static variable
  2. Making the IScheduler a global static variable
  3. I have added an email notification to the end of the Application_Start so I know when it is firing
  4. 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);
}
Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top