Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Job Stops Running?

Tags:

iis

quartz.net

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.

like image 357
msbg Avatar asked Oct 23 '25 17:10

msbg


2 Answers

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.

like image 162
Thierry Avatar answered Oct 26 '25 14:10

Thierry


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

like image 45
SeeSharp Avatar answered Oct 26 '25 15:10

SeeSharp