Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if job is stopping before checking interrupt #4632

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ChunkListener;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInterruptedException;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecution;
Expand Down Expand Up @@ -71,6 +72,7 @@
* @author Michael Minella
* @author Will Schipp
* @author Mahmoud Ben Hassine
* @author Seonkyo Ok
*/
public class TaskletStep extends AbstractStep {

Expand Down Expand Up @@ -238,7 +240,7 @@ protected void doExecute(StepExecution stepExecution) throws Exception {
public RepeatStatus doInChunkContext(RepeatContext repeatContext, ChunkContext chunkContext)
throws Exception {

StepExecution stepExecution = chunkContext.getStepContext().getStepExecution();
final StepExecution stepExecution = chunkContext.getStepContext().getStepExecution();

// Before starting a new transaction, check for
// interruption.
Expand All @@ -256,6 +258,12 @@ public RepeatStatus doInChunkContext(RepeatContext repeatContext, ChunkContext c

chunkListener.afterChunk(chunkContext);

final JobExecution jobExecution = stepExecution.getJobExecution();
if (jobExecution.isStopping()) {
logger.info("Parent JobExecution is stopped, so passing message on to StepExecution");
stepExecution.setTerminateOnly();
}

// Check for interruption after transaction as well, so that
// the interrupted exception is correctly propagated up to
// caller
Expand Down Expand Up @@ -367,7 +375,7 @@ public RepeatStatus doInTransaction(TransactionStatus status) {

RepeatStatus result = RepeatStatus.CONTINUABLE;

StepContribution contribution = stepExecution.createStepContribution();
final StepContribution contribution = stepExecution.createStepContribution();

chunkListener.beforeChunk(chunkContext);

Expand Down Expand Up @@ -437,7 +445,7 @@ public RepeatStatus doInTransaction(TransactionStatus status) {
catch (Exception e) {
// If we get to here there was a problem saving the step
// execution and we have to fail.
String msg = "JobRepository failure forcing rollback";
final String msg = "JobRepository failure forcing rollback";
logger.error(msg, e);
throw new FatalStepExecutionException(msg, e);
}
Expand Down Expand Up @@ -476,7 +484,7 @@ private void rollback(StepExecution stepExecution) {
}
}

private void copy(final StepExecution source, final StepExecution target) {
private static void copy(final StepExecution source, final StepExecution target) {
target.setVersion(source.getVersion());
target.setWriteCount(source.getWriteCount());
target.setFilterCount(source.getFilterCount());
Expand Down