Search in sources :

Example 1 with JobParametersIncrementer

use of org.springframework.batch.core.JobParametersIncrementer in project spring-boot by spring-projects.

the class JobLauncherCommandLineRunner method getNextJobParameters.

private JobParameters getNextJobParameters(Job job, JobParameters additionalParameters) {
    String name = job.getName();
    JobParameters parameters = new JobParameters();
    List<JobInstance> lastInstances = this.jobExplorer.getJobInstances(name, 0, 1);
    JobParametersIncrementer incrementer = job.getJobParametersIncrementer();
    Map<String, JobParameter> additionals = additionalParameters.getParameters();
    if (lastInstances.isEmpty()) {
        // Start from a completely clean sheet
        if (incrementer != null) {
            parameters = incrementer.getNext(new JobParameters());
        }
    } else {
        List<JobExecution> previousExecutions = this.jobExplorer.getJobExecutions(lastInstances.get(0));
        JobExecution previousExecution = previousExecutions.get(0);
        if (previousExecution == null) {
            // Normally this will not happen - an instance exists with no executions
            if (incrementer != null) {
                parameters = incrementer.getNext(new JobParameters());
            }
        } else if (isStoppedOrFailed(previousExecution) && job.isRestartable()) {
            // Retry a failed or stopped execution
            parameters = previousExecution.getJobParameters();
            // Non-identifying additional parameters can be removed to a retry
            removeNonIdentifying(additionals);
        } else if (incrementer != null) {
            // New instance so increment the parameters if we can
            parameters = incrementer.getNext(previousExecution.getJobParameters());
        }
    }
    return merge(parameters, additionals);
}
Also used : JobExecution(org.springframework.batch.core.JobExecution) JobInstance(org.springframework.batch.core.JobInstance) JobParameters(org.springframework.batch.core.JobParameters) JobParametersIncrementer(org.springframework.batch.core.JobParametersIncrementer) JobParameter(org.springframework.batch.core.JobParameter)

Aggregations

JobExecution (org.springframework.batch.core.JobExecution)1 JobInstance (org.springframework.batch.core.JobInstance)1 JobParameter (org.springframework.batch.core.JobParameter)1 JobParameters (org.springframework.batch.core.JobParameters)1 JobParametersIncrementer (org.springframework.batch.core.JobParametersIncrementer)1