Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
2.19.0
-
None
-
Unknown
Description
Recently I noticed that on application start Quartz founds and triggers misfired triggers:
INFO o.s.s.q.LocalDataSourceJobStore - Handling 1 trigger(s) that missed their scheduled fire-time.
That wasn't not the realistic case in my scenario - since I could see in a database that NEXT_FIRE_TIME is much ahead of the current time.
After digging a little I found the issue in the QuartzScheduledPollConsumerScheduler:
// Ensure the cron schedule is updated
CronTrigger newTrigger = existingTrigger.getTriggerBuilder().withSchedule(CronScheduleBuilder.cronSchedule(getCron()).inTimeZone(getTimeZone())).build();
quartzScheduler.rescheduleJob(triggerKey, newTrigger);
There 2 issues here:
1. Job is rescheduled even if nothing has been changed (i.e. cron expression, cron timezone)
2. existingTrigger.getTriggerBuilder() returns trigger builder with START_TIME of existing trigger which, surely, is the past. This is causing the described bug - NEXT_FIRE_TIME is calculated based on the old START_TIME and is in the past also. So rescheduled trigger becomes misfired trigger immediately.
Proposal:
1. Do not reschedule job if nothing has been changed.
2. If job needs to be rescheduled - make sure to set START_TIME to a current date.