问题描述
我在我的 asp.net Core Web 应用程序中使用 Quartz.Net 每 5 分钟触发一次作业。但过了一会儿它就无缘无故地停止了……你能看看我的配置或/和 Quartz'logs 吗?
这是我在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
);
工作开始并做它应该做的任何事情。它重复该过程几次,然后关闭。
这是 START 事件的日志:
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.
这是 END 事件的日志:
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.
我认为 cron 配置是错误的,但是这个配置的事件,我得到了相同的行为。
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
);
你能告诉我这个配置有什么问题吗?
该作业应该在数据库中查找一些特定数据,并使用 ExpoSDK 将它们推送到 android 和 ios 应用程序。
谢谢
解决方法
我发现 program.cs main 方法在网站没有访问者时退出。 我一直在寻找一种方法来强制它连续运行,但我没有成功(我没想过要查看 IIS)......所以我将我的程序移到了我们的前端应用程序(而不是后端)上始终至少有一位访客。