Johnny_D
Johnny_D

Reputation: 4652

Quartz.net suddenly stops triggering jobs

I've implemented quartz.net for scheduling tasks in my project. After some test I've deployed it on Prod env and it started to behave very strange. As this scheduler is user in windows service, I used logs for debugging. Every job writes some info via log4net in log file. After 3-4 days of work service stops writing any info in log file. All errors are prompted to be written to log file too, there isn't any of it. After manual restart everything starts as it supposed to be for 3-4 days and then it happens again.

This is how scheduler is started:

_jobsTimeTable = ComponentFactory.Resolve<TimeTable>();

// construct a scheduler factory
ISchedulerFactory schedFact = new StdSchedulerFactory();
// get a scheduler
IScheduler sched = schedFact.GetScheduler();

// Configuration of triggers and jobs
int i = 0;
string mainGroup = "mainGroup";
foreach (var job in _jobsTimeTable.TimeTable)
{
    var trigger = (ICronTrigger)TriggerBuilder.Create()
                                          .WithIdentity("trigger" + i, mainGroup)
                                          .WithCronSchedule(job.Value)
                                          .Build();

    var jobDetail = JobBuilder.Create(Type.GetType(job.Key)).StoreDurably(true)
                                .WithIdentity("job" + i, mainGroup).Build();

    var ft = sched.ScheduleJob(jobDetail, trigger);

    _log.InfoFormat("{0} has been scheduled to run at: {1} and repeat based on expression: {2}",
                    jobDetail.Key, ft.ToLocalTime(), trigger.CronExpressionString);

    i++;
}

sched.Start();

I would really appreciate any ideas.

Upvotes: 1

Views: 1506

Answers (1)

Marko Lahma
Marko Lahma

Reputation: 6884

From your code it would seem that you don't hold a global reference to IScheduler which eventually leads to garbage collection. You should always have a static reference for the lifetime of your application to prevent cleanup.

Upvotes: 2

Related Questions