Skip to content

Commit

Permalink
Check if job is stopping before checking interrupt
Browse files Browse the repository at this point in the history
  • Loading branch information
uyw4687 committed Jul 15, 2024
1 parent 425134c commit ba1f2a5
Showing 1 changed file with 12 additions and 4 deletions.
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

0 comments on commit ba1f2a5

Please sign in to comment.