4

I have a job that I want to run every ten minutes. To schedule it, I use:

public static IScheduler _scheduler { get; private set; }

...

        ISchedulerFactory schedFact = new StdSchedulerFactory();
        _scheduler = schedFact.GetScheduler();
        _scheduler.Start();

        string cron = "0 0/10 * 1/1 * ? *";

        JobKey jobkey = new JobKey("Radar", "F");
        IJobDetail job = JobBuilder.Create<RadarJob>()
                                    .WithIdentity(jobkey)
                                    .Build();

        CronScheduleBuilder csb = CronScheduleBuilder.CronSchedule(new CronExpression(cron)).InTimeZone(TimeZoneInfo.Local);
        ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create()
                                                            .WithIdentity("Radar-Trigger", "G")
                                                            .WithSchedule(csb)
                                                            .Build();
        try
        {
            DateTimeOffset ft = _scheduler.ScheduleJob(job, trigger);
            Response.Write("Job Scheduled");
        }
        catch (ObjectAlreadyExistsException)
        {
            Response.Write("Job Already Exists!");
        }

It seems to work at first, the job runs fine every ten minutes. However, after an hour or so, it stops running. I log successes and errors, and I have no errors. What is causing my job to stop by itself?

I am running IIS 7, .NET Framework 4.0, Using a Shared Hosting Plan from GoDaddy.

2

2 Answers 2

4

Your job is running inside of the IIS AppPool. The pool is probably recycling, which will kill the quartz task, and IIS will not automatically restart it (as it DOES restart web requests which are in process when the pool recycles).

(I'm assuming that you are running the above code in Application_Start() inside of your Global.asax file.)

We had this situation and decided to use quartz as a standalone service which would not be affected by pool recycles, though I'm not sure if this would be a viable option for you under a shared hosting plan.

You indicate that you are running on IIS 7. If in fact this is IIS 7.5, there may be a better solution outlined in Auto-Start application / global.asax / wcf service when IIS7 starts automatically, which would be to configure the app pool to automatically restart.

2
  • Thank you. Unfortunately I don't have IIS 7.5. I do not have control over the services on my shared hosting plan. I will probably end up using a computer that is always on to load the task on my site. Or maybe just fork over the extra cash to for a dedicated server.
    – msbg
    May 28, 2013 at 19:31
  • Does your hosting allow you to use windows scheduled tasks? If so, you could have a scheduled task hit the website every five minutes (which IIRC is the minimum repeat time) as a keep-alive.
    – Thierry
    May 30, 2013 at 13:46
1

This is late for answering but I had this kind off error in my application. I solved it by IIS config that I found it in Scott Gu weblog : http://weblogs.asp.net/scottgu/auto-start-asp-net-applications-vs-2010-and-net-4-0-series

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.