Skip to content

Commit 8a77ca3

Browse files
lcmarvinfmbenhassine
authored andcommitted
Upgrade job execution status from STOPPING to STOPPED if it has already ended
Resolves #4064
1 parent 84b1e1f commit 8a77ca3

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -172,6 +172,12 @@ public void update(JobExecution jobExecution) {
172172
jobExecution.setLastUpdated(new Date(System.currentTimeMillis()));
173173

174174
jobExecutionDao.synchronizeStatus(jobExecution);
175+
if (jobExecution.getStatus() == BatchStatus.STOPPING && jobExecution.getEndTime() != null) {
176+
if (logger.isInfoEnabled()) {
177+
logger.info("Upgrading job execution status from STOPPING to STOPPED since it has already ended.");
178+
}
179+
jobExecution.upgradeStatus(BatchStatus.STOPPED);
180+
}
175181
jobExecutionDao.updateJobExecution(jobExecution);
176182
}
177183

spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2020 the original author or authors.
2+
* Copyright 2006-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -295,4 +295,15 @@ public void testGetStepExecutionCount() {
295295
// Then
296296
assertEquals(expectedResult, actualResult);
297297
}
298+
299+
@Test
300+
public void testUpgradeStopping() {
301+
jobExecution.setStatus(BatchStatus.STOPPING);
302+
jobExecution.setEndTime(new Date());
303+
304+
jobRepository.update(jobExecution);
305+
306+
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
307+
}
308+
298309
}

0 commit comments

Comments
 (0)