Current version : 3.0.6
Current .NET framework : .NET Framework 4.6.2
Issue: Scheduler stops at random intervals and discontinues scheduler - Must restart app pool to re-initiate / build task triggers to continue running jobs.
Our system currently uses around 30 background tasks at different times, from every minute to once a month. We have tried using the simple schedule, DailyTimeInterval schedule, and crons.
Here are some examples of the code we use in each iteration:
This wrapper function builds all of our tasks by type and trigger:
private static async Task ScheduleAsync(BackgroundTaskType type, ITrigger trigger)
{
var jobKey = JobKey.Create(type.ToString());
var job = JobBuilder.Create<QuartzJob>().WithIdentity(jobKey).Build();
ReschedulableJobs.Add(type, job);
scheduler.ScheduleJob(job, trigger);
}
Simple:
await Schedule(BackgroundTaskType.HelloWorld,
TriggerBuilder.Create()
.WithSimpleSchedule(x => x.WithIntervalInMinutes(6).RepeatForever()).StartNow().Build()
);
DailyTimeInterval:
await ScheduleAsync(BackgroundTaskType.TheTask,
TriggerBuilder.Create()
.WithDailyTimeIntervalSchedule(
x => x.WithIntervalInMinutes(60)
.OnEveryDay()
.StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(0, 0)) // midnight central
.InTimeZone(TimeZoneInfo.Local)
).Build());
Cron:
await ScheduleAsync(BackgroundTaskType.TheTask,
TriggerBuilder.Create()
.WithCronSchedule("0 0 12 * * ?")
.Build()); // fire every day at noon
await scheduler.Start();
Currently, the simple schedule will fire when we want it to without issue, but on deploy it will fire multiple of each task simultaneously - and because the schedule is based on time since deploy, the actual run times can be
erratic and unpredictables - not what we want. So that brought us to the daily time interval schedule, which gave us exactly what we wanted, however, the scheduler would randomly stop firing tasks - assuming this is due to some
sort of deadlock somewhere. We don't get any exceptions, any warnings, nothing. All that happens is, tasks will cease to fire, and we will need to restart the app pool. This is a huge issue for us, and the only workaround
that we have found is by writing an application to restart the app pool after 15 minutes of no tasks running. Obviously not ideal.
Crons will not fire at all with our current implementation. That was our last hope at getting some consistency.
Right now the issue is that we would like to deviate from simple scheduling BUT ALSO would like our scheduler to be consistent and run 24/7 without any hiccups. The hangup with tasks ceasing to fire is a huge deterrent to this.
Extra question:
Is this due to all tasks being async? (We used to run with mostly simple scheduler w/o async code.)
Thanks in advance,