-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
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
Line 348 in c8a0528
| jobExecution.setEndTime(LocalDateTime.now()); |
Directly afterwards the
jobRepository.update(jobExecution);
checks
Line 139 in c8a0528
| 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
Lines 186 to 188 in c8a0528
| 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?