It seems like Spring Batch 6 cannot stop a Job anymore.
After calling stop(), all steps are executed and later the job is marked as FAILED.
In Spring Batch 5 the flow was:
STARTED -> STOPPING -> mark step executions as terminateOnly -> STOPPED
In Spring Batch 6 it is:
STARTED -> STOPPING -> STOPPED -> FAILED
If I am right then the root cause of this change is the following new line in
|
jobExecution.setEndTime(LocalDateTime.now()); |
Directly afterwards the
jobRepository.update(jobExecution);
checks
|
if (jobExecution.getStatus() == BatchStatus.STOPPING && jobExecution.getEndTime() != null) { |
This will always be false as the endTime was set just before.
The jobState will be set from STOPPING to STOPPED directly.
Consequence
Inside SimpleJobRepository#update(StepExecution) -> checkForInterruption(stepExecution) the check in
|
if (jobExecution.isStopping()) { |
|
logger.info("Parent JobExecution is stopped, so passing message on to StepExecution"); |
|
stepExecution.setTerminateOnly(); |
will never be true and the steps are not marked for terminateOnly.
Is this intended and how can I prevent running the unstarted steps once the job is stopped?
It seems like Spring Batch 6 cannot stop a Job anymore.
After calling stop(), all steps are executed and later the job is marked as FAILED.
In Spring Batch 5 the flow was:
STARTED->STOPPING-> mark step executions as terminateOnly ->STOPPEDIn Spring Batch 6 it is:
STARTED->STOPPING->STOPPED->FAILEDIf I am right then the root cause of this change is the following new line in
spring-batch/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java
Line 348 in c8a0528
Directly afterwards the
jobRepository.update(jobExecution);checks
spring-batch/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java
Line 139 in c8a0528
This will always be false as the endTime was set just before.
The jobState will be set from
STOPPINGtoSTOPPEDdirectly.Consequence
Inside
SimpleJobRepository#update(StepExecution)->checkForInterruption(stepExecution)the check inspring-batch/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java
Lines 186 to 188 in c8a0528
will never be true and the steps are not marked for terminateOnly.
Is this intended and how can I prevent running the unstarted steps once the job is stopped?