Skip to content

stop() does not prevent upcoming steps to be executed anymore #5114

@andre-bugay

Description

@andre-bugay

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

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions