Search in sources :

Example 1 with JobParameters

use of org.springframework.batch.core.JobParameters in project head by mifos.

the class MifosBatchJob method catchUpMissedLaunches.

public void catchUpMissedLaunches(Job job, JobExecutionContext context) throws Exception {
    List<JobInstance> jobInstances = jobExplorer.getJobInstances(job.getName(), 0, 1);
    if (jobInstances.size() > 0) {
        JobInstance jobInstance = jobInstances.get(0);
        Date previousFireTime = new Date(jobInstance.getJobParameters().getLong(JOB_EXECUTION_TIME_KEY));
        Date scheduledFireTime = context.getScheduledFireTime();
        Trigger trigger = context.getTrigger();
        boolean onDemandRun = false;
        if (Scheduler.DEFAULT_MANUAL_TRIGGERS.equals(trigger.getGroup())) {
            // this is a manual run
            trigger = context.getScheduler().getTrigger(job.getName(), Scheduler.DEFAULT_GROUP);
            scheduledFireTime = new DateTimeService().getCurrentDateTime().toDate();
            onDemandRun = true;
        }
        List<Date> missedLaunches = computeMissedJobLaunches(previousFireTime, scheduledFireTime, trigger, onDemandRun);
        for (Date missedLaunch : missedLaunches) {
            JobParameters jobParameters = createJobParameters(missedLaunch.getTime());
            launchJob(job, jobParameters);
        }
    }
}
Also used : Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CronTrigger(org.quartz.CronTrigger) JobInstance(org.springframework.batch.core.JobInstance) JobParameters(org.springframework.batch.core.JobParameters) DateTimeService(org.mifos.framework.util.DateTimeService) Date(java.util.Date)

Example 2 with JobParameters

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

the class BatchJobLauncher method alarmJob.

public void alarmJob() {
    JobParameters params = createTimeParameter();
    run("alarmJob", params);
}
Also used : JobParameters(org.springframework.batch.core.JobParameters)

Example 3 with JobParameters

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

the class JobLauncherCommandLineRunnerTests method retryFailedExecution.

@Test
public void retryFailedExecution() throws Exception {
    this.job = this.jobs.get("job").start(this.steps.get("step").tasklet(new Tasklet() {

        @Override
        public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
            throw new RuntimeException("Planned");
        }
    }).build()).incrementer(new RunIdIncrementer()).build();
    this.runner.execute(this.job, new JobParameters());
    this.runner.execute(this.job, new JobParameters());
    assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
}
Also used : StepContribution(org.springframework.batch.core.StepContribution) JobParameters(org.springframework.batch.core.JobParameters) Tasklet(org.springframework.batch.core.step.tasklet.Tasklet) ChunkContext(org.springframework.batch.core.scope.context.ChunkContext) RunIdIncrementer(org.springframework.batch.core.launch.support.RunIdIncrementer) Test(org.junit.Test)

Example 4 with JobParameters

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

the class JobLauncherCommandLineRunnerTests method basicExecution.

@Test
public void basicExecution() throws Exception {
    this.runner.execute(this.job, new JobParameters());
    assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
    this.runner.execute(this.job, new JobParametersBuilder().addLong("id", 1L).toJobParameters());
    assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(2);
}
Also used : JobParametersBuilder(org.springframework.batch.core.JobParametersBuilder) JobParameters(org.springframework.batch.core.JobParameters) Test(org.junit.Test)

Example 5 with JobParameters

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

the class JobLauncherCommandLineRunnerTests method incrementExistingExecution.

@Test
public void incrementExistingExecution() throws Exception {
    this.job = this.jobs.get("job").start(this.step).incrementer(new RunIdIncrementer()).build();
    this.runner.execute(this.job, new JobParameters());
    this.runner.execute(this.job, new JobParameters());
    assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(2);
}
Also used : JobParameters(org.springframework.batch.core.JobParameters) RunIdIncrementer(org.springframework.batch.core.launch.support.RunIdIncrementer) Test(org.junit.Test)

Aggregations

JobParameters (org.springframework.batch.core.JobParameters)20 Test (org.junit.Test)12 Date (java.util.Date)5 JobRepository (org.springframework.batch.core.repository.JobRepository)5 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 RunIdIncrementer (org.springframework.batch.core.launch.support.RunIdIncrementer)4 Job (org.springframework.batch.core.Job)3 JobParameter (org.springframework.batch.core.JobParameter)3 JobParametersBuilder (org.springframework.batch.core.JobParametersBuilder)3 StepContribution (org.springframework.batch.core.StepContribution)3 ChunkContext (org.springframework.batch.core.scope.context.ChunkContext)3 Tasklet (org.springframework.batch.core.step.tasklet.Tasklet)3 HashMap (java.util.HashMap)2 JobExecution (org.springframework.batch.core.JobExecution)2 JobInstance (org.springframework.batch.core.JobInstance)2 Map (java.util.Map)1 CamelExchangeException (org.apache.camel.CamelExchangeException)1 DateTimeService (org.mifos.framework.util.DateTimeService)1 CronTrigger (org.quartz.CronTrigger)1 SimpleTrigger (org.quartz.SimpleTrigger)1