Skip to content

Commit 1498f90

Browse files
lcmarvinfmbenhassine
authored andcommitted
Upgrade job execution status from STOPPING to STOPPED if it has already ended
Resolves #4064
1 parent c0547c6 commit 1498f90

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ public void update(JobExecution jobExecution) {
187187
jobExecution.setLastUpdated(LocalDateTime.now());
188188

189189
jobExecutionDao.synchronizeStatus(jobExecution);
190+
if (jobExecution.getStatus() == BatchStatus.STOPPING && jobExecution.getEndTime() != null) {
191+
if (logger.isInfoEnabled()) {
192+
logger.info("Upgrading job execution status from STOPPING to STOPPED since it has already ended.");
193+
}
194+
jobExecution.upgradeStatus(BatchStatus.STOPPED);
195+
}
190196
jobExecutionDao.updateJobExecution(jobExecution);
191197
}
192198

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,4 +319,14 @@ void testGetStepExecutionCount() {
319319
assertEquals(expectedResult, actualResult);
320320
}
321321

322+
@Test
323+
public void testUpgradeStopping() {
324+
jobExecution.setStatus(BatchStatus.STOPPING);
325+
jobExecution.setEndTime(LocalDateTime.now());
326+
327+
jobRepository.update(jobExecution);
328+
329+
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
330+
}
331+
322332
}

0 commit comments

Comments
 (0)