Reputation: 3
I have a job that runs 1st minute of every hour.
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.
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.
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?
Does quartz has anyway to check misfire count inside job ?
Appreciate your help !!
Upvotes: 0
Views: 1735
Reputation: 340733
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).
To be precise, in your case at 10:30 the job will trigger twice and getScheduledFireTime()
will return 9:00 and 10:00.
Upvotes: 4