From e2cb609a2d2b3b1631251accb547273a865bb0df Mon Sep 17 00:00:00 2001 From: Javier Date: Tue, 27 Aug 2024 17:10:36 +0200 Subject: [PATCH] Try to cancel timer always, and only search if timer cancellation fails --- .../services/ejb/timer/EJBTimerScheduler.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/jbpm-services/jbpm-services-ejb/jbpm-services-ejb-timer/src/main/java/org/jbpm/services/ejb/timer/EJBTimerScheduler.java b/jbpm-services/jbpm-services-ejb/jbpm-services-ejb-timer/src/main/java/org/jbpm/services/ejb/timer/EJBTimerScheduler.java index 48f09f2c6f..250d757886 100644 --- a/jbpm-services/jbpm-services-ejb/jbpm-services-ejb-timer/src/main/java/org/jbpm/services/ejb/timer/EJBTimerScheduler.java +++ b/jbpm-services/jbpm-services-ejb/jbpm-services-ejb-timer/src/main/java/org/jbpm/services/ejb/timer/EJBTimerScheduler.java @@ -114,6 +114,7 @@ public void executeTimerJob(Timer timer) { try { executeTimerJobInstance(timerJobInstance); } catch (Exception e) { + logger.error("Error executing timer handle {}", timerJobInstance.getJobHandle(), e); recoverTimerJobInstance(timerJob, timer, e); } } @@ -139,7 +140,7 @@ else if (ejbTimerJob.getTimerJobInstance().getTrigger().hasNextFireTime() != nul // because of the transaction, so we need to do this here. tx = timerJobInstance -> { logger.warn("Execution of time failed Interval Trigger failed. Skipping {}", timerJobInstance); - if (removeJob(timerJobInstance.getJobHandle(), null)) { + if (removeJob(timerJobInstance.getJobHandle(), timer, true)) { internalSchedule(timerJobInstance); } else { logger.debug("Interval trigger {} was removed before rescheduling", timerJobInstance); @@ -246,7 +247,11 @@ private Serializable removeTransientFields(Serializable info) { return info; } - public boolean removeJob(JobHandle jobHandle, Timer ejbTimer) { + public boolean removeJob(JobHandle jobHandle, Timer ejbTimer) { + return removeJob(jobHandle, ejbTimer, false); + } + + public boolean removeJob(JobHandle jobHandle, Timer ejbTimer, boolean searchIfFailed) { EjbGlobalJobHandle ejbHandle = (EjbGlobalJobHandle) jobHandle; if (useLocalCache) { boolean removedFromCache = localCache.remove(ejbHandle.getUuid()) != null; @@ -257,9 +262,11 @@ public boolean removeJob(JobHandle jobHandle, Timer ejbTimer) { try { ejbTimer.cancel(); return true; - } catch (Throwable e) { - logger.debug("Timer cancel error due to {}", e.getMessage()); - return false; + } catch (Exception e) { + logger.warn("Timer cancel error for handle {}", ejbHandle, e); + if (!searchIfFailed) { + return false; + } } } @@ -271,7 +278,7 @@ public boolean removeJob(JobHandle jobHandle, Timer ejbTimer) { try { ((TimerHandle) ejbTimerHandle).getTimer().cancel(); } catch (Throwable e) { - logger.debug("Timer cancel error due to {}", e.getMessage()); + logger.warn("Timer cancel error for handle {}", ejbTimerHandle, e); return false; } return true; @@ -288,12 +295,12 @@ public boolean removeJob(JobHandle jobHandle, Timer ejbTimer) { EjbGlobalJobHandle handle = (EjbGlobalJobHandle) job.getTimerJobInstance().getJobHandle(); if (handle.getUuid().equals(ejbHandle.getUuid())) { - logger.debug("Job handle {} does match timer and is going to be canceled", jobHandle); + logger.info("Job handle {} does match timer and is going to be canceled", jobHandle); try { timer.cancel(); } catch (Throwable e) { - logger.debug("Timer cancel error due to {}", e.getMessage()); + logger.warn("Timer cancel error for handle {}", handle, e); return false; } return true; @@ -303,7 +310,7 @@ public boolean removeJob(JobHandle jobHandle, Timer ejbTimer) { logger.debug("Timer {} has already expired or was canceled ", timer); } } - logger.debug("Job handle {} does not match any timer on {} scheduler service", jobHandle, this); + logger.info("Job handle {} does not match any timer on {} scheduler service", jobHandle, this); return false; }