Skip to content

Commit eea6a54

Browse files
committed
Upgrade STOPPING to STOPPED when updating JobExecution if it ends.
1 parent 75b1492 commit eea6a54

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
@@ -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("Upgrade STOPPING to STOPPED since JobExecution 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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,14 @@ public void testGetStepExecutionCount() {
296296
// Then
297297
assertEquals(expectedResult, actualResult);
298298
}
299+
300+
@Test
301+
public void testUpgradeStopping() {
302+
jobExecution.setStatus(BatchStatus.STOPPING);
303+
jobExecution.setEndTime(new Date());
304+
305+
jobRepository.update(jobExecution);
306+
307+
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
308+
}
299309
}

0 commit comments

Comments
 (0)