org.springframework.batch.core.launch.support.RunIdIncrementer Java Examples

The following examples show how to use org.springframework.batch.core.launch.support.RunIdIncrementer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TaskJobLauncherCommandLineRunnerCoreTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@DirtiesContext
@Test
public void retryFailedExecutionOnNonRestartableJob() throws Exception {
	this.job = this.jobs.get("job").preventRestart()
			.start(this.steps.get("step").tasklet(throwingTasklet()).build())
			.incrementer(new RunIdIncrementer()).build();
	runFailedJob(new JobParameters());
	runFailedJob(new JobParameters());
	// A failed job that is not restartable does not re-use the job params of
	// the last execution, but creates a new job instance when running it again.
	assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(2);

	// try to re-run a failed execution
	Executable executable = () -> this.runner.execute(this.job,
			new JobParametersBuilder().addLong("run.id", 1L).toJobParameters());
	assertThatExceptionOfType(JobRestartException.class)
			.isThrownBy(executable::execute)
			.withMessage("JobInstance already exists and is not restartable");
}
 
Example #2
Source File: ComposedRunnerJobFactory.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Override
public Job getObject() throws Exception {
	ComposedRunnerVisitor composedRunnerVisitor = new ComposedRunnerVisitor();

	TaskParser taskParser = new TaskParser("composed-task-runner",
			this.dsl,false,true);
	taskParser.parse().accept(composedRunnerVisitor);

	this.visitorDeque = composedRunnerVisitor.getFlow();

	FlowJobBuilder builder = this.jobBuilderFactory
			.get(this.taskNameResolver.getTaskName())
			.start(this.flowBuilder
					.start(createFlow())
					.end())
			.end();
	if(this.incrementInstanceEnabled) {
		builder.incrementer(new RunIdIncrementer());
	}
	return builder.build();
}
 
Example #3
Source File: SettleJobConfiguration.java    From seed with Apache License 2.0 6 votes vote down vote up
@Bean
public Job settleJob() {
    return jobBuilderFactory.get("settleJob")
            //使每个Job的运行ID都唯一
            .incrementer(new RunIdIncrementer())
            .listener(this.settleJobListeners)
            //.flow(step0001).split(new SimpleAsyncTaskExecutor("springbatch_seedboot")).add(flow04, flow05, flow06)
            //.start(step0001).split(new SimpleAsyncTaskExecutor("springbatch_seedboot")).add(flow04, flow05, flow06)
            //先执行step0001(注意:上面注释的这两种写法都不会step0001先执行然后再执行step0004...,他们都会使得step0001和step0004...同时执行)
            .flow(step0001)
            //然后step0004、step0005、step0006开始执行且三者是并行执行互不影响的
            .next(this.splitFlow())
            //接着等三者全都执行完毕才会去执行step0002
            .next(step0002)
            //最后执行step0003
            .next(step0003)
            .end()
            .build();
}
 
Example #4
Source File: ComposedRunnerJobFactory.java    From composed-task-runner with Apache License 2.0 6 votes vote down vote up
@Override
public Job getObject() throws Exception {
	ComposedRunnerVisitor composedRunnerVisitor = new ComposedRunnerVisitor();

	TaskParser taskParser = new TaskParser("composed-task-runner",
			this.dsl,false,true);
	taskParser.parse().accept(composedRunnerVisitor);

	this.visitorDeque = composedRunnerVisitor.getFlow();

	FlowJobBuilder builder = this.jobBuilderFactory
			.get(this.taskNameResolver.getTaskName())
			.start(this.flowBuilder
					.start(createFlow())
					.end())
			.end();
	if(this.incrementInstanceEnabled) {
		builder.incrementer(new RunIdIncrementer());
	}
	return builder.build();
}
 
Example #5
Source File: CsvBatchConfig.java    From Demo with Apache License 2.0 5 votes vote down vote up
@Bean
public Job importJob(JobBuilderFactory jobs, Step s1) {
    return jobs.get("importJob")
            .incrementer(new RunIdIncrementer())
            .flow(s1) //为 job 指定 step
            .end()
            .listener(csvJobListener()) //绑定监听器 csvJobListener
            .build();
}
 
Example #6
Source File: TaskJobLauncherCommandLineRunnerCoreTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@DirtiesContext
@Test
public void retryFailedExecutionWithDifferentNonIdentifyingParametersFromPreviousExecution()
		throws Exception {
	this.job = this.jobs.get("job")
			.start(this.steps.get("step").tasklet(throwingTasklet()).build())
			.incrementer(new RunIdIncrementer()).build();
	JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false)
			.addLong("foo", 2L, false).toJobParameters();
	runFailedJob(jobParameters);
	assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
	// try to re-run a failed execution with non identifying parameters
	runFailedJob(new JobParametersBuilder().addLong("run.id", 1L)
			.addLong("id", 2L, false).addLong("foo", 3L, false).toJobParameters());
	assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
	JobInstance jobInstance = this.jobExplorer.getJobInstance(0L);
	assertThat(this.jobExplorer.getJobExecutions(jobInstance)).hasSize(2);
	// first execution
	JobExecution firstJobExecution = this.jobExplorer.getJobExecution(0L);
	JobParameters parameters = firstJobExecution.getJobParameters();
	assertThat(parameters.getLong("run.id")).isEqualTo(1L);
	assertThat(parameters.getLong("id")).isEqualTo(1L);
	assertThat(parameters.getLong("foo")).isEqualTo(2L);
	// second execution
	JobExecution secondJobExecution = this.jobExplorer.getJobExecution(1L);
	parameters = secondJobExecution.getJobParameters();
	// identifying parameters should be the same as previous execution
	assertThat(parameters.getLong("run.id")).isEqualTo(1L);
	// non-identifying parameters should be the newly specified ones
	assertThat(parameters.getLong("id")).isEqualTo(2L);
	assertThat(parameters.getLong("foo")).isEqualTo(3L);
}
 
Example #7
Source File: TaskJobLauncherCommandLineRunnerCoreTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@DirtiesContext
@Test
public void retryFailedExecutionWithNonIdentifyingParameters() throws Exception {
	this.job = this.jobs.get("job")
			.start(this.steps.get("step").tasklet(throwingTasklet()).build())
			.incrementer(new RunIdIncrementer()).build();
	JobParameters jobParameters = new JobParametersBuilder().addLong("id", 1L, false)
			.addLong("foo", 2L, false).toJobParameters();
	runFailedJob(jobParameters);
	assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
	runFailedJob(new JobParametersBuilder(jobParameters).addLong("run.id", 1L)
			.toJobParameters());
	assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
}
 
Example #8
Source File: TaskJobLauncherCommandLineRunnerCoreTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@DirtiesContext
@Test
public void retryFailedExecution() throws Exception {
	this.job = this.jobs.get("job")
			.start(this.steps.get("step").tasklet(throwingTasklet()).build())
			.incrementer(new RunIdIncrementer()).build();
	runFailedJob(new JobParameters());
	runFailedJob(new JobParametersBuilder().addLong("run.id", 1L).toJobParameters());
	assertThat(this.jobExplorer.getJobInstances("job", 0, 100)).hasSize(1);
}
 
Example #9
Source File: TaskJobLauncherCommandLineRunnerCoreTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@DirtiesContext
@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);
}
 
Example #10
Source File: ReportsExecutionJob.java    From POC with Apache License 2.0 5 votes vote down vote up
@Bean(name = "executionJob")
public Job reportsExecutionJob(CustomItemReader<List<Long>> reader, CustomItemProcessor processor,
		CustomItemWriter<List<PostDTO>> writer, TaskExecutor taskExecutor) {

	Step step = this.stepBuilderFactory.get("execution-step").allowStartIfComplete(true)
			.<List<Long>, List<PostDTO>>chunk(1).reader(reader).processor(processor).writer(writer)
			.taskExecutor(taskExecutor).build();

	return this.jobBuilderFactory.get("reporting-job").incrementer(new RunIdIncrementer()).listener(this)
			.start(step).build();
}
 
Example #11
Source File: AddressPrinterJobConfiguration.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@Bean
public Job addressPrinterJob(final JobBuilderFactory jobBuilderFactory,
                             final Step addressPrinterStep,
                             final Step addressBatchTaskDeletionStep) throws Exception {
    return jobBuilderFactory
            .get("addressPrinterJob")
            .incrementer(new RunIdIncrementer())
            .start(addressPrinterStep)
            .next(addressBatchTaskDeletionStep)
            .build();
}
 
Example #12
Source File: BatchConfiguration.java    From spring-boot-samples with Apache License 2.0 5 votes vote down vote up
@Bean
public Job importUserJob(JobCompletionNotificationListener listener) {
    return jobBuilderFactory.get("importUserJob")
            .incrementer(new RunIdIncrementer())
            .listener(listener)
            .flow(step1())
            .end()
            .build();
}
 
Example #13
Source File: BatchConfiguration.java    From journaldev with MIT License 5 votes vote down vote up
@Bean
public Job job(Step step1) throws Exception {
  return jobBuilderFactory.get("job1")
      .incrementer(new RunIdIncrementer())
      .start(step1)
      .build();
}
 
Example #14
Source File: BatchConfig.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
@Bean
public Job importUserJob(JobBuilderFactory jobs, Step step1, Step step2, JobExecutionListener listener) {
       return jobs.get("importUserJob")
               .incrementer(new RunIdIncrementer())
               .listener(listener)
               .flow(step1)
               .next(step2)
               .end()
               .build();
 }
 
Example #15
Source File: AdHocSchedulerTest.java    From spring-batch-rest with Apache License 2.0 5 votes vote down vote up
private Job job(String jobName, CountDownLatch latch) {
	return scheduler.jobs().get(jobName).incrementer(new RunIdIncrementer()) // adds unique parameter on each run so
																				// that createJob can be rerun
			.start(scheduler.steps().get("step").tasklet((contribution, chunkContext) -> {
				latch.countDown();
				return RepeatStatus.FINISHED;
			}).allowStartIfComplete(true).build()).build();
}
 
Example #16
Source File: AdHocSchedulerParamsTest.java    From spring-batch-rest with Apache License 2.0 5 votes vote down vote up
private Job job(String jobName) {
	return scheduler.jobs().get(jobName).incrementer(new RunIdIncrementer()) // adds unique parameter on each run so
																				// that createJob can be rerun
			.start(scheduler.steps().get("step").tasklet((contribution, chunkContext) -> {
				return RepeatStatus.FINISHED;
			}).allowStartIfComplete(true).build()).build();
}
 
Example #17
Source File: PersonJobConfig.java    From spring-batch-rest with Apache License 2.0 5 votes vote down vote up
@Bean
Job personJob(@Qualifier("personStep") Step personStep) {
    return adHocScheduler.schedule(PersonJobConfig.JOB_NAME, jobs.get(JOB_NAME)
            .incrementer(new RunIdIncrementer())
            .flow(personStep)
            .end()
            .build(), "0 0 12 * * ?");
}
 
Example #18
Source File: BatchConfiguration.java    From batch-processing-large-datasets-spring with MIT License 5 votes vote down vote up
@Bean
public Job importVoltageJob(NotificationListener listener, Step step1) {
    return jobBuilderFactory.get("importVoltageJob")
            .incrementer(new RunIdIncrementer())
            .listener(listener)
            .flow(step1)
            .end()
            .build();
}
 
Example #19
Source File: FlatFileBatchJob.java    From spring-cloud with Apache License 2.0 5 votes vote down vote up
@Bean
public Job jobUseFlatFileWithRepositoryItemWriter(RepositoryItemWriterJobListener listener) {
    return jobBuilderFactory
            .get("jobUseFlatFileWithRepositoryItemWriter")
            .incrementer(new RunIdIncrementer())
            .listener(listener)
            .flow(repositoryItemWriterStep)
            .end()
            .build();
}
 
Example #20
Source File: FlatFileBatchJob.java    From spring-cloud with Apache License 2.0 5 votes vote down vote up
@Bean
public Job jobUseFlatFileWithJdbcBatchItemWriter(JdbcBatchItemWriterJobListener listener) {
    return jobBuilderFactory.get("jobUseFlatFileWithJdbcBatchItemWriter")
            .incrementer(new RunIdIncrementer())
            .listener(listener)
            .flow(jdbcBatchItemWriterStep)
            .end()
            .build();
}
 
Example #21
Source File: RepositoryJob.java    From spring-cloud with Apache License 2.0 5 votes vote down vote up
@Bean
public Job jobWithRepositoryStepWithParams(@Autowired CommonJobListener commonJobListener) {
    return jobBuilderFactory.get("jobWithRepositoryStepWithParams")
            .incrementer(new RunIdIncrementer())
            .listener(commonJobListener)
            .flow(stepWithRepositoryReaderAndWriter)
            .end()
            .build();
}
 
Example #22
Source File: RepositoryJob.java    From spring-cloud with Apache License 2.0 5 votes vote down vote up
@Bean
public Job jobWithRepositoryStep(@Autowired CommonJobListener commonJobListener) {
    return jobBuilderFactory.get("jobWithRepositoryStep")
            .incrementer(new RunIdIncrementer())
            .listener(commonJobListener)
            .flow(stepWithRepository)
            .end()
            .build();
}
 
Example #23
Source File: JpaPagingBatchJob.java    From spring-cloud with Apache License 2.0 5 votes vote down vote up
@Bean
public Job jobInJpaPagingWithJdbcBatchItemWriter(JpaPagingBatchJobListener listener) {
    return jobBuilderFactory
            .get("jobInJpaPagingWithJdbcBatchItemWriter")
            .incrementer(new RunIdIncrementer())
            .listener(listener)
            .flow(stepInJpaPagingWithJdbcBatchItemWriter)
            .end()
            .build();
}
 
Example #24
Source File: JpaPagingBatchJob.java    From spring-cloud with Apache License 2.0 5 votes vote down vote up
@Bean
public Job jobInJpaPagingWithRepositoryItemWriter(JpaPagingBatchJobListener listener) {
    return jobBuilderFactory
            .get("jobInJpaPagingWithJdbcBatchItemWriter")
            .incrementer(new RunIdIncrementer())
            .listener(listener)
            .flow(stepInJpaPagingWithRepositoryItemWriter)
            .end()
            .build();
}
 
Example #25
Source File: BatchConfig.java    From Software-Architecture-with-Spring-5.0 with MIT License 5 votes vote down vote up
@Bean
public Job importPayRollJob(JobCompletionPayRollListener listener, Step step1) {
    return jobBuilderFactory.get("importPayRollJob")
            .incrementer(new RunIdIncrementer())
            .listener(listener)
            .flow(step1)
            .end()
            .build();
}
 
Example #26
Source File: SimpleBatchApplication.java    From Software-Architecture-with-Spring-5.0 with MIT License 5 votes vote down vote up
@Bean
public Job job(Step ourBatchStep) throws Exception {
	return jobBuilderFactory.get("jobPackPub1")
			.incrementer(new RunIdIncrementer())
			.start(ourBatchStep)
			.build();
}
 
Example #27
Source File: BudgetVtollConfig.java    From SpringBootBucket with MIT License 5 votes vote down vote up
/**
 * Job定义,我们要实际执行的任务,包含一个或多个Step
 *
 * @param jobBuilderFactory
 * @param s1
 * @return
 */
@Bean(name = "vtollJob")
public Job vtollJob(JobBuilderFactory jobBuilderFactory, @Qualifier("vtollStep1") Step s1) {
    return jobBuilderFactory.get("vtollJob")
            .incrementer(new RunIdIncrementer())
            .flow(s1)//为Job指定Step
            .end()
            .listener(new MyJobListener())//绑定监听器csvJobListener
            .build();
}
 
Example #28
Source File: CantonConfig.java    From SpringBootBucket with MIT License 5 votes vote down vote up
/**
 * Job定义,我们要实际执行的任务,包含一个或多个Step
 *
 * @param jobBuilderFactory
 * @param s1
 * @return
 */
@Bean(name = "cantonJob")
public Job cantonJob(JobBuilderFactory jobBuilderFactory, @Qualifier("cantonStep1") Step s1) {
    return jobBuilderFactory.get("cantonJob")
            .incrementer(new RunIdIncrementer())
            .flow(s1)//为Job指定Step
            .end()
            .listener(new MyJobListener())//绑定监听器csvJobListener
            .build();
}
 
Example #29
Source File: LogConfig.java    From SpringBootBucket with MIT License 5 votes vote down vote up
/**
 * Job定义,我们要实际执行的任务,包含一个或多个Step
 *
 * @param jobBuilderFactory
 * @param s1
 * @return
 */
@Bean(name = "zlogJob")
public Job zlogJob(JobBuilderFactory jobBuilderFactory, @Qualifier("logStep1") Step s1) {
    return jobBuilderFactory.get("zlogJob")
            .incrementer(new RunIdIncrementer())
            .flow(s1)//为Job指定Step
            .end()
            .listener(new MyJobListener())//绑定监听器csvJobListener
            .build();
}
 
Example #30
Source File: AppConfig.java    From SpringBootBucket with MIT License 5 votes vote down vote up
/**
 * Job定义,我们要实际执行的任务,包含一个或多个Step
 *
 * @param jobBuilderFactory
 * @param s1
 * @return
 */
@Bean(name = "zappJob")
public Job zappJob(JobBuilderFactory jobBuilderFactory, @Qualifier("zappStep1") Step s1) {
    return jobBuilderFactory.get("zappJob")
            .incrementer(new RunIdIncrementer())
            .flow(s1)//为Job指定Step
            .end()
            .listener(new MyJobListener())//绑定监听器csvJobListener
            .build();
}