Skip to content
Closed
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 @@ -39,6 +39,8 @@
import org.springframework.batch.core.converter.JobParametersConverter;
import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.launch.support.ExitCodeMapper;
import org.springframework.batch.core.launch.support.SimpleJvmExitCodeMapper;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.repository.JobRepository;
Expand All @@ -54,6 +56,8 @@
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

import static org.springframework.batch.core.launch.support.ExitCodeMapper.JVM_EXITCODE_COMPLETED;

/**
* {@link ApplicationRunner} to {@link JobLauncher launch} Spring Batch jobs. If a single
* job is found in the context, it will be executed by default. If multiple jobs are
Expand All @@ -64,7 +68,8 @@
* @author Mahmoud Ben Hassine
* @author Stephane Nicoll
* @author Akshay Dubey
* @since 2.3.0
* @author Minjun Kang
* @since 3.3.1
*/
public class JobLauncherApplicationRunner
implements ApplicationRunner, InitializingBean, Ordered, ApplicationEventPublisherAware {
Expand Down Expand Up @@ -92,6 +97,8 @@ public class JobLauncherApplicationRunner

private int order = DEFAULT_ORDER;

private ExitCodeMapper exitCodeMapper = new SimpleJvmExitCodeMapper();

private ApplicationEventPublisher publisher;

/**
Expand Down Expand Up @@ -173,6 +180,7 @@ protected void launchJobFromProperties(Properties properties) throws JobExecutio
JobParameters jobParameters = this.converter.getJobParameters(properties);
executeLocalJobs(jobParameters);
executeRegisteredJobs(jobParameters);
validateJobTerminateStatus();
}

private boolean isLocalJob(String jobName) {
Expand Down Expand Up @@ -204,6 +212,15 @@ private void executeRegisteredJobs(JobParameters jobParameters) throws JobExecut
}
}

private void validateJobTerminateStatus() throws JobExecutionException {
String exitCode = jobExplorer.getLastJobExecution(jobExplorer.getLastJobInstance(this.jobName))
.getExitStatus().getExitCode();

if (exitCodeMapper.intValue(exitCode) != JVM_EXITCODE_COMPLETED) {
throw new JobExecutionException("Job Terminated with BatchStatus : " + exitCode);
}
}

protected void execute(Job job, JobParameters jobParameters) throws JobExecutionAlreadyRunningException,
JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException {
JobParameters parameters = getNextJobParameters(job, jobParameters);
Expand Down