Issue
I'm using Quartz.Net in my asp.net Core web application to trigger a job every 5 minutes. But it stops with no reason after a while... Could you have a look at my configuration or/and to the Quartz'logs ?
This is my configuration in program.cs
services.AddQuartz(q =>
{
q.UseMicrosoftDependencyInjectionScopedJobFactory();
var jobKey = new JobKey("AppPushJob");
q.AddJob<AppPushJob>(opts => opts.WithIdentity(jobKey));
// Create a trigger for the job
q.AddTrigger(opts => opts
.ForJob(jobKey) // link to the AppPushJob
.WithIdentity("AppPushJob-trigger") // give the trigger a unique name
.WithCronSchedule("0 0/5 6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 * * ?")); ; // run every 5 minutes de 6h à 23h, tous les jours
});
// Add the Quartz.NET hosted service
services.AddQuartzHostedService(
q => q.WaitForJobsToComplete = true
);
The job start and do whatever it is supposed to do. It repeats the process a few times and then shuts down.
This is the log for START event :
2021-02-04 14:05:28.026 +01:00 Information Initialized Scheduler Signaller of type: Quartz.Core.SchedulerSignalerImpl
2021-02-04 14:05:28.026 +01:00 Information Quartz Scheduler v."3.2.3.0" created.
2021-02-04 14:05:28.027 +01:00 Information JobFactory set to: Quartz.Simpl.MicrosoftDependencyInjectionJobFactory
2021-02-04 14:05:28.027 +01:00 Information RAMJobStore initialized.
2021-02-04 14:05:28.032 +01:00 Information Scheduler meta-data: Quartz Scheduler (v3.2.3.0) 'QuartzScheduler' with instanceId 'NON_CLUSTERED'
Scheduler class: 'Quartz.Core.QuartzScheduler' - running locally.
NOT STARTED.
Currently in standby mode.
Number of jobs executed: 0
Using thread pool 'Quartz.Simpl.DefaultThreadPool' - with 10 threads.
Using job-store 'Quartz.Simpl.RAMJobStore' - which does not support persistence. and is not clustered.
This is the log for END event :
2021-02-04 14:25:30.767 +01:00 Debug Trigger instruction : NoInstruction
2021-02-04 14:25:51.659 +01:00 Debug Batch acquisition of 0 triggers
2021-02-04 14:26:14.861 +01:00 Debug Batch acquisition of 0 triggers
2021-02-04 14:26:26.741 +01:00 Information Scheduler "QuartzScheduler_$_NON_CLUSTERED" shutting down.
2021-02-04 14:26:26.744 +01:00 Information Scheduler QuartzScheduler_$_NON_CLUSTERED paused.
2021-02-04 14:26:26.752 +01:00 Debug Shutting down threadpool...
2021-02-04 14:26:26.752 +01:00 Debug Waiting for 0 threads to complete.
2021-02-04 14:26:26.752 +01:00 Debug No executing jobs remaining, all threads stopped.
2021-02-04 14:26:26.752 +01:00 Debug Shutdown of threadpool complete.
2021-02-04 14:26:26.758 +01:00 Information Scheduler QuartzScheduler_$_NON_CLUSTERED Shutdown complete.
I thought the cron configuration was wrong but event with this config, I get the same behavior.
q.AddTrigger(opts => opts
.ForJob(jobKey) // link to the AppPushJob
.WithIdentity("AppPushJob-trigger") // give the trigger a unique name
.WithSimpleSchedule(x => x
.WithIntervalInMinutes(5)
.RepeatForever()) //--> I thought this will be enough
);
Could you tell le what is wrong with this configuration please ?
The job is supposed to look for some specific data in database, and push them to android and ios application with ExpoSDK.
Thanks
Solution
I've found out the program.cs main method was exiting when the website had no visitor anymore. I've looked for a way to force it to run continuously, but I didn't succeed (I haven't thought to look on IIS)... so I moved my program on our frontend application (rather then the backend) which has always at least one visitor.
Answered By - ordiminnie