Search in sources :

Example 1 with JobParameter

use of org.springframework.batch.core.JobParameter in project pinpoint by naver.

the class AlarmJobTest method getParameters.

private static JobParameters getParameters() {
    Map<String, JobParameter> parameters = new HashMap<String, JobParameter>();
    parameters.put("schedule.scheduledFireTime", new JobParameter(new Date()));
    return new JobParameters(parameters);
}
Also used : HashMap(java.util.HashMap) JobParameters(org.springframework.batch.core.JobParameters) JobParameter(org.springframework.batch.core.JobParameter) Date(java.util.Date)

Example 2 with JobParameter

use of org.springframework.batch.core.JobParameter 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)

Example 3 with JobParameter

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

the class JobLauncherCommandLineRunner method merge.

private JobParameters merge(JobParameters parameters, Map<String, JobParameter> additionals) {
    Map<String, JobParameter> merged = new HashMap<>();
    merged.putAll(parameters.getParameters());
    merged.putAll(additionals);
    parameters = new JobParameters(merged);
    return parameters;
}
Also used : HashMap(java.util.HashMap) JobParameters(org.springframework.batch.core.JobParameters) JobParameter(org.springframework.batch.core.JobParameter)

Aggregations

JobParameter (org.springframework.batch.core.JobParameter)3 JobParameters (org.springframework.batch.core.JobParameters)3 HashMap (java.util.HashMap)2 Date (java.util.Date)1 JobExecution (org.springframework.batch.core.JobExecution)1 JobInstance (org.springframework.batch.core.JobInstance)1 JobParametersIncrementer (org.springframework.batch.core.JobParametersIncrementer)1