From a758b11b0c558759f2a2c10495fb38e39c7c3068 Mon Sep 17 00:00:00 2001 From: Filip Hrisafov Date: Thu, 26 Nov 2026 07:31:27 +0100 Subject: [PATCH] Do not mark the execution as inactive when retrying a failed job Marking the execution as inactive meant that the activity end was never recorded for executions whose activity instance had already been started (e.g. a boundary timer event). It also removed the execution from the active activity ids while waiting for the retry. --- .../flowable/engine/impl/cmd/JobRetryCmd.java | 2 - ...BoundaryTimerNonInterruptingEventTest.java | 43 +++++++++++++++++++ ...st.testTimerRetriedAfterFailure.bpmn20.xml | 34 +++++++++++++++ 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/timer/BoundaryTimerNonInterruptingEventTest.testTimerRetriedAfterFailure.bpmn20.xml diff --git a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/JobRetryCmd.java b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/JobRetryCmd.java index 9d4c45ebb33..507a88e7b73 100644 --- a/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/JobRetryCmd.java +++ b/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/JobRetryCmd.java @@ -80,8 +80,6 @@ public Object execute(CommandContext commandContext) { } if (executionEntity != null) { - executionEntity.setActive(false); - if (StringUtils.isNotEmpty(failedJobRetryTimeCycleValue)) { ExpressionManager expressionManager = processEngineConfig.getExpressionManager(); if (expressionManager != null) { diff --git a/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/event/timer/BoundaryTimerNonInterruptingEventTest.java b/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/event/timer/BoundaryTimerNonInterruptingEventTest.java index 9de28e245b7..7615e315b1e 100644 --- a/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/event/timer/BoundaryTimerNonInterruptingEventTest.java +++ b/modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/event/timer/BoundaryTimerNonInterruptingEventTest.java @@ -15,12 +15,17 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; +import org.flowable.common.engine.api.FlowableException; +import org.flowable.common.engine.impl.history.HistoryLevel; +import org.flowable.engine.history.HistoricActivityInstance; +import org.flowable.engine.impl.test.HistoryTestHelper; import org.flowable.engine.impl.test.PluggableFlowableTestCase; import org.flowable.engine.runtime.Execution; import org.flowable.engine.runtime.ProcessInstance; @@ -221,6 +226,44 @@ public void testTimerWithCycle() throws Exception { .doesNotThrowAnyException(); } + @Test + @Deployment + public void testTimerRetriedAfterFailure() { + ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder() + .processDefinitionKey("nonInterruptingTimerRetry") + .variable("failTimer", true) + .start(); + + Job timerJob = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult(); + managementService.moveTimerToExecutableJob(timerJob.getId()); + assertThatThrownBy(() -> managementService.executeJob(timerJob.getId())) + .isInstanceOf(FlowableException.class) + .hasStackTraceContaining("Timer failed"); + + Job retriedTimerJob = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult(); + assertThat(retriedTimerJob.getRetries()).isEqualTo(2); + + runtimeService.setVariable(processInstance.getId(), "failTimer", false); + managementService.moveTimerToExecutableJob(retriedTimerJob.getId()); + managementService.executeJob(retriedTimerJob.getId()); + + assertThat(runtimeService.getActiveActivityIds(processInstance.getId())).containsExactlyInAnyOrder("task", "timer"); + + Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult(); + taskService.complete(task.getId()); + assertProcessEnded(processInstance.getId()); + + if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) { + assertThat(historyService.createHistoricActivityInstanceQuery() + .processInstanceId(processInstance.getId()) + .activityId("timer") + .list()) + .extracting(HistoricActivityInstance::getEndTime) + .hasSize(2) + .doesNotContainNull(); + } + } + /* * see https://activiti.atlassian.net/browse/ACT-1173 */ diff --git a/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/timer/BoundaryTimerNonInterruptingEventTest.testTimerRetriedAfterFailure.bpmn20.xml b/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/timer/BoundaryTimerNonInterruptingEventTest.testTimerRetriedAfterFailure.bpmn20.xml new file mode 100644 index 00000000000..8a46fa76b81 --- /dev/null +++ b/modules/flowable-engine/src/test/resources/org/flowable/engine/test/bpmn/event/timer/BoundaryTimerNonInterruptingEventTest.testTimerRetriedAfterFailure.bpmn20.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + PT1H + + + + + + + + + + + + +