Skip to content

Commit

Permalink
Upgrade job execution status from STOPPING to STOPPED if it has alrea…
Browse files Browse the repository at this point in the history
…dy ended

Resolves #4064
  • Loading branch information
lcmarvin authored and fmbenhassine committed Nov 18, 2022
1 parent 84b1e1f commit 8a77ca3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -172,6 +172,12 @@ public void update(JobExecution jobExecution) {
jobExecution.setLastUpdated(new Date(System.currentTimeMillis()));

jobExecutionDao.synchronizeStatus(jobExecution);
if (jobExecution.getStatus() == BatchStatus.STOPPING && jobExecution.getEndTime() != null) {
if (logger.isInfoEnabled()) {
logger.info("Upgrading job execution status from STOPPING to STOPPED since it has already ended.");
}
jobExecution.upgradeStatus(BatchStatus.STOPPED);
}
jobExecutionDao.updateJobExecution(jobExecution);
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2020 the original author or authors.
* Copyright 2006-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -295,4 +295,15 @@ public void testGetStepExecutionCount() {
// Then
assertEquals(expectedResult, actualResult);
}

@Test
public void testUpgradeStopping() {
jobExecution.setStatus(BatchStatus.STOPPING);
jobExecution.setEndTime(new Date());

jobRepository.update(jobExecution);

assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
}

}

0 comments on commit 8a77ca3

Please sign in to comment.