【问题标题】:Why Quartz.net is shutting down despite RepeatForever()为什么 Quartz.net 正在关闭,尽管 RepeatForever()
【发布时间】:2021-02-04 14:19:45
【问题描述】:

我在我的 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 应用程序。

谢谢

【问题讨论】:

  • 您的程序是否因某种原因退出? Quartz 将作为 Program.cs 退出的一部分关闭。您的主要方法是否有没有退出条件的 host.Run() / host.RunAsync()?
  • 感谢您的帮助。 Program.cs 的代码没有理由退出。但是我注意到当没有人再访问该网站时它会退出。一旦我在浏览器中调用 home url,服务就会再次启动。即使网站上没有人,我该怎么做才能激发它?我想在我的主要 AppPushJob 方法中设置一个 while(true),但在这种情况下,我没有得到 repeatForever() 的目的...
  • 由网络服务器决定它是否要强制停止站点,因此也要强制停止 Quartz。您需要配置 always on 以防止网站进入休眠/回收状态。
  • 不错的解决方案,虽然我还没有查看 IIS...下次!谢谢

标签: asp.net-core cron quartz.net


【解决方案1】:

当网站不再有访问者时,我发现 program.cs 主要方法正在退出。 我一直在寻找一种方法来强制它连续运行,但我没有成功(我没有想过要在 IIS 上查看)......所以我将我的程序移到了我们的前端应用程序(而不是后端)上总是至少有一位访客。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-08
    • 2022-10-13
    • 1970-01-01
    • 2016-05-07
    相关资源
    最近更新 更多