Skip to content

Commit 9d05b6f

Browse files
authored
Do not mark the execution as inactive when retrying a failed job (#4340)
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.
1 parent 5ee80a7 commit 9d05b6f

3 files changed

Lines changed: 77 additions & 2 deletions

File tree

‎modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/JobRetryCmd.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ public Object execute(CommandContext commandContext) {
8080
}
8181

8282
if (executionEntity != null) {
83-
executionEntity.setActive(false);
84-
8583
if (StringUtils.isNotEmpty(failedJobRetryTimeCycleValue)) {
8684
ExpressionManager expressionManager = processEngineConfig.getExpressionManager();
8785
if (expressionManager != null) {

‎modules/flowable-engine/src/test/java/org/flowable/engine/test/bpmn/event/timer/BoundaryTimerNonInterruptingEventTest.java‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@
1515

1616
import static org.assertj.core.api.Assertions.assertThat;
1717
import static org.assertj.core.api.Assertions.assertThatCode;
18+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1819

1920
import java.util.Collections;
2021
import java.util.Date;
2122
import java.util.HashMap;
2223
import java.util.List;
2324

25+
import org.flowable.common.engine.api.FlowableException;
26+
import org.flowable.common.engine.impl.history.HistoryLevel;
27+
import org.flowable.engine.history.HistoricActivityInstance;
28+
import org.flowable.engine.impl.test.HistoryTestHelper;
2429
import org.flowable.engine.impl.test.PluggableFlowableTestCase;
2530
import org.flowable.engine.runtime.Execution;
2631
import org.flowable.engine.runtime.ProcessInstance;
@@ -221,6 +226,44 @@ public void testTimerWithCycle() throws Exception {
221226
.doesNotThrowAnyException();
222227
}
223228

229+
@Test
230+
@Deployment
231+
public void testTimerRetriedAfterFailure() {
232+
ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder()
233+
.processDefinitionKey("nonInterruptingTimerRetry")
234+
.variable("failTimer", true)
235+
.start();
236+
237+
Job timerJob = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult();
238+
managementService.moveTimerToExecutableJob(timerJob.getId());
239+
assertThatThrownBy(() -> managementService.executeJob(timerJob.getId()))
240+
.isInstanceOf(FlowableException.class)
241+
.hasStackTraceContaining("Timer failed");
242+
243+
Job retriedTimerJob = managementService.createTimerJobQuery().processInstanceId(processInstance.getId()).singleResult();
244+
assertThat(retriedTimerJob.getRetries()).isEqualTo(2);
245+
246+
runtimeService.setVariable(processInstance.getId(), "failTimer", false);
247+
managementService.moveTimerToExecutableJob(retriedTimerJob.getId());
248+
managementService.executeJob(retriedTimerJob.getId());
249+
250+
assertThat(runtimeService.getActiveActivityIds(processInstance.getId())).containsExactlyInAnyOrder("task", "timer");
251+
252+
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
253+
taskService.complete(task.getId());
254+
assertProcessEnded(processInstance.getId());
255+
256+
if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.ACTIVITY, processEngineConfiguration)) {
257+
assertThat(historyService.createHistoricActivityInstanceQuery()
258+
.processInstanceId(processInstance.getId())
259+
.activityId("timer")
260+
.list())
261+
.extracting(HistoricActivityInstance::getEndTime)
262+
.hasSize(2)
263+
.doesNotContainNull();
264+
}
265+
}
266+
224267
/*
225268
* see https://activiti.atlassian.net/browse/ACT-1173
226269
*/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<definitions id="definitions"
3+
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
4+
xmlns:flowable="http://flowable.org/bpmn"
5+
targetNamespace="Examples">
6+
7+
<process id="nonInterruptingTimerRetry">
8+
9+
<startEvent id="theStart"/>
10+
<sequenceFlow id="flow1" sourceRef="theStart" targetRef="task"/>
11+
12+
<userTask id="task"/>
13+
<sequenceFlow id="flow2" sourceRef="task" targetRef="end"/>
14+
15+
<boundaryEvent id="timer" attachedToRef="task" cancelActivity="false">
16+
<timerEventDefinition>
17+
<timeDuration>PT1H</timeDuration>
18+
</timerEventDefinition>
19+
</boundaryEvent>
20+
<sequenceFlow id="flow3" sourceRef="timer" targetRef="timerFiredTask"/>
21+
<scriptTask id="timerFiredTask" scriptFormat="groovy">
22+
<script>
23+
if (failTimer) {
24+
throw new RuntimeException("Timer failed")
25+
}
26+
</script>
27+
</scriptTask>
28+
<sequenceFlow id="flow4" sourceRef="timerFiredTask" targetRef="nonInterruptingEnd"/>
29+
<endEvent id="nonInterruptingEnd"/>
30+
31+
<endEvent id="end"/>
32+
33+
</process>
34+
</definitions>

0 commit comments

Comments
 (0)