本文介绍了石英从多天失火中恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次尝试设置 Quartz,如果我不理解某些东西,请原谅我.我想知道完成以下任务的最佳方法是什么:

I'm trying to set up Quartz for the first time, and forgive me if I am just not understanding something. I'm wondering what is the best way to accomplish the following:

如何设置必须运行每日电子邮件报告并能够从错过的触发器中恢复的作业,以便:1) 作业知道触发器应该在哪一天触发.和 2) 如果(上帝保佑)服务器宕机 3 天,Quartz 将通过连续运行 3 天来恢复,同时通知作业每个作业代表的日期.(执行顺序并不重要,只要我知道每个代表哪一天)

How to set up a job that must run a daily email report, and also be able to recover from a missed trigger so that: 1) the job knows what day the trigger was SUPPOSED to fire on. and 2) if (god forbid) the server is down for 3 days, Quartz will recover by running three missed days consecutively, also informing the job of what day each job represents. (execution order is not really important as long as I know what day each represents)

现在我只是在做:

Trigger trigger = newTrigger()
.withIdentity("dailyTrigger", "scheduledReportEmail")
.startNow()
.withSchedule(dailyAtHourAndMinute(0, 5) .withMisfireHandlingInstructionFireAndProceed())
.build();

无论错过多少天,这似乎只能通过运行一次来​​恢复.那是对的吗?

This only seems to recover by running once, no matter how many days get missed. Is that correct?

我想到的一种方法基本上是设置 31 个每日触发器,用于第 1-31 天.笨重的......那些额外的日子在二月会发生什么?这是最好的方法吗?

One approach I thought about is basically setting up 31 daily triggers, for days 1-31. Clunky.. and what might happen in February for those extra days? Is this the best approach?

我还有每周和每月的触发器要处理,但我想如果我们停工三周,那么我们有更大的事情要担心:)

I've also got weekly and monthly triggers to deal with but I figure if we're down for three weeks then we have bigger things to worry about :)

感谢您的建议....

推荐答案

您的用例非常标准并且 Quartz 支持.您只需要忽略失火"政策:

Your use case is pretty standard and supported by Quartz. You just need "ignore misfires" policy:

Trigger trigger = newTrigger()
  .withIdentity("dailyTrigger", "scheduledReportEmail")
  .withSchedule(dailyAtHourAndMinute(0, 5)
  .withMisfireHandlingInstructionIgnoreMisfires())
  .build();

这基本上意味着:我不在乎触发器是否未触发,只要尽快运行(这很可能在应用程序启动时运行).

This basically means: I don't care that the trigger(s) misfired, just run it as soon as possible (that is most likely at application startup).

要确定给定触发器的运行时间(计划时间与当前时间相反),请在您的作业中运行:

To figure out when given trigger was suppose to run (what was the scheduled time as opposed to current time), run this in your job:

void execute(JobExecutionContext context) {
  final Date scheduled = context.getScheduledFireTime()
  //...
}

另见

07-26 01:04