问题描述
我有一个每小时运行 1 分钟的工作.
I have a job that runs 1st minute of every hour.
Job 将获取当前小时并查询 DB 以查看该小时要发送的任何通知,如果有,它将发送电子邮件通知.
Job will get current hour and query DB to see any notifications to be sent for this hour, if any, it will send email notifications.
现在的问题是处理失火.
Now the problem is with handling misfires.
说当调度程序在上午 8 点 30 分到 10 点 30 分之间关闭时,我错过了 2 个触发器.当调度程序在 10:30 出现时,我需要这 2 个错过的触发器才能被触发.所以我使用的是带有MisfireHandlingInstructionIgnoreMisfires 触发器的石英.
say when the scheduler is down between say 8:30AM - 10:30AM, i missed 2 triggers.When the scheduler comes up at 10:30 i need these 2 missed triggers to get fired.so i am using quartz withMisfireHandlingInstructionIgnoreMisfires trigger.
由于我的工作具有基于当前时间查询的逻辑,因此两个失火触发器都将查询仅在上午 10 点(不是上午 8 点和上午 9 点)发送的通知
Since my job has logic which queries based on current hour of the day, both misfire triggers will query notifications to send for 10AM only (not 8AM and 9AM)
我将如何处理这种情况?
How will i handle this scenario?
quartz 是否需要检查工作中的失火计数?
Does quartz has anyway to check misfire count inside job ?
感谢您的帮助!!
推荐答案
在您的情况下,您应该获得预定日期,而不是依赖当前系统日期:
In your case, instead of relying on current system date you should get scheduled date:
void execute(JobExecutionContext context) {
context.getScheduledFireTime()
//...
}
通常当前系统时间应该非常接近预定的触发时间.但是在失火情况下或重载情况下,预定的点火时间比当前时间早很多(我们会遇到延迟).
Typically current system time should be very close to scheduled fire time. But in misfire situation or under heavy load scheduled fire time is way before current time (we experience delay).
准确地说,在您的情况下,在 10:30 作业将触发两次,getScheduledFireTime()
将返回 9:00 和 10:00.
To be precise, in your case at 10:30 the job will trigger twice and getScheduledFireTime()
will return 9:00 and 10:00.
这篇关于使用带有MisfireHandlingInstructionIgnoreMisfires的quartz时的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!