davsclaus commented on code in PR #24670:
URL: https://github.com/apache/camel/pull/24670#discussion_r3576408159
##########
components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java:
##########
@@ -328,14 +332,16 @@ protected void doStart() throws Exception {
throw new IllegalArgumentException("Cannot have both options
deleteJob and pauseJob enabled");
}
if (ObjectHelper.isNotEmpty(customCalendar)) {
-
getComponent().getScheduler().addCalendar(QuartzConstants.QUARTZ_CAMEL_CUSTOM_CALENDAR,
customCalendar, true,
- false);
+ getComponent().getScheduler().addCalendar(customCalendarName(),
customCalendar, true, false);
}
addJobInScheduler();
}
@Override
protected void doStop() throws Exception {
Review Comment:
**Bug:** `deleteCalendar()` is called before `removeJobInScheduler()`.
Quartz's `RAMJobStore.removeCalendar()` iterates all triggers and throws
`JobPersistenceException("Calender cannot be removed if it referenced by a
Trigger!")` if any trigger still references the calendar name.
Since `removeJobInScheduler()` (which calls
`scheduler.unscheduleJob(triggerKey)`) hasn't run yet at this point, the
trigger still exists and references the calendar — so this will throw on every
endpoint stop with the default `deleteJob=true`.
Additionally, `deleteCalendar` should only be attempted when the trigger was
actually removed. When `deleteJob=false` (trigger is paused or left running),
or when the scheduler is clustered (the `!isClustered` guard in
`removeJobInScheduler` skips the unschedule), the trigger persists and
`deleteCalendar` would also throw.
```suggestion
protected void doStop() throws Exception {
removeJobInScheduler();
if (deleteJob && ObjectHelper.isNotEmpty(customCalendar)) {
Scheduler scheduler = getComponent().getScheduler();
if (scheduler != null && !scheduler.isShutdown()) {
try {
scheduler.deleteCalendar(customCalendarName());
} catch (SchedulerException e) {
LOG.debug("Could not delete calendar {}: {}",
customCalendarName(), e.getMessage());
}
}
}
}
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]