@Bean public Job importUserJob(JobCompletionNotificationListener listener, Step step1) { return jobBuilderFactory.get("importUserJob") .incrementer(new RunIdIncrementer()) .listener(listener) .flow(step1) .end() .build(); }
@Bean public Job job() { return jobBuilderFactory.get("job").flow(step()).end().build(); }
/** * Branch into a flow conditional on the outcome of the current step. * * @param pattern a pattern for the exit status of the current step * @return a builder for fluent chaining */ public FlowBuilder.TransitionBuilder<FlowJobBuilder> on(String pattern) { Assert.state(steps.size() > 0, "You have to start a job with a step"); for (Step step : steps) { if (builder == null) { builder = new JobFlowBuilder(new FlowJobBuilder(this), step); } else { builder.next(step); } } return builder.on(pattern); }
/** * @param executor instance of {@link TaskExecutor} to be used. * @return builder for fluent chaining */ public JobFlowBuilder.SplitBuilder<FlowJobBuilder> split(TaskExecutor executor) { for (Step step : steps) { if (builder == null) { builder = new JobFlowBuilder(new FlowJobBuilder(this), step); } else { builder.next(step); } } if (builder == null) { builder = new JobFlowBuilder(new FlowJobBuilder(this)); } return builder.split(executor); }
/** * Start with this decider. Returns a flow builder and when the flow is ended a job builder will be returned to * continue the job configuration if needed. * * @param decider a decider to execute first * @return builder for fluent chaining */ public JobFlowBuilder start(JobExecutionDecider decider) { if (builder == null) { builder = new JobFlowBuilder(new FlowJobBuilder(this), decider); } else { builder.start(decider); } if (!steps.isEmpty()) { steps.remove(0); } for (Step step : steps) { builder.next(step); } return builder; }
@Test public void testBuildSubflow() throws Exception { Flow flow = new FlowBuilder<Flow>("subflow").from(step1).end(); JobFlowBuilder builder = new JobBuilder("flow").repository(jobRepository).start(flow); builder.on("COMPLETED").to(step2); builder.end().preventRestart().build().execute(execution); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); assertEquals(2, execution.getStepExecutions().size()); }
/** * Continue with this decider if the previous step was successful. Returns a flow builder and when the flow is ended * a job builder will be returned to continue the job configuration if needed. * * @param decider a decider to execute next * @return builder for fluent chaining */ public JobFlowBuilder next(JobExecutionDecider decider) { for (Step step : steps) { if (builder == null) { builder = new JobFlowBuilder(new FlowJobBuilder(this), step); } else { builder.next(step); } } if (builder == null) { builder = new JobFlowBuilder(new FlowJobBuilder(this), decider); } else { builder.next(decider); } return builder; }
public JobFlowBuilder(FlowJobBuilder parent, Flow flow) { super(parent.getName()); this.parent = parent; start(flow); }
/** * Start a job with this flow, but expect to transition from there to other flows or steps. * * @param flow the flow to start with * @return a builder to enable fluent chaining */ public JobFlowBuilder start(Flow flow) { return new JobFlowBuilder(this, flow); }
@Test public void testBuildDecision() throws Exception { JobExecutionDecider decider = new JobExecutionDecider() { private int count = 0; @Override public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) { count++; return count<2 ? new FlowExecutionStatus("ONGOING") : FlowExecutionStatus.COMPLETED; } }; step1.setAllowStartIfComplete(true); SimpleJobBuilder builder = new JobBuilder("flow").repository(jobRepository).start(step1); builder.next(decider).on("COMPLETED").end().from(decider).on("*").to(step1).end(); builder.preventRestart().build().execute(execution); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); assertEquals(2, execution.getStepExecutions().size()); }
/** * Build a flow and inject it into the parent builder. The parent builder is then returned so it can be enhanced * before building an actual job. Normally called explicitly via {@link #end()}. * * @see org.springframework.batch.core.job.builder.FlowBuilder#build() */ @Override public FlowJobBuilder build() { Flow flow = flow(); if(flow instanceof InitializingBean) { try { ((InitializingBean) flow).afterPropertiesSet(); } catch (Exception e) { throw new FlowBuilderException(e); } } parent.flow(flow); return parent; }
@Bean public Job indexMarkdownDocumentsJob(JobBuilderFactory jobBuilderFactory, Step indexingStep, Step optimizeStep) { return jobBuilderFactory.get("indexMarkdownDocuments") .incrementer(new RunIdIncrementer()) .flow(indexingStep) .next(optimizeStep) .end() .build(); }
@Bean public Job job() { return jobBuilderFactory.get("job") .start(flow1()) .split(new SimpleAsyncTaskExecutor()).add(flow2()) .end() .build(); }
/** * Start with this decider. Returns a flow builder and when the flow is ended a job builder will be returned to * continue the job configuration if needed. * * @param decider a decider to execute first * @return builder for fluent chaining */ public JobFlowBuilder start(JobExecutionDecider decider) { if (builder == null) { builder = new JobFlowBuilder(new FlowJobBuilder(this), decider); } else { builder.start(decider); } if (!steps.isEmpty()) { steps.remove(0); } for (Step step : steps) { builder.next(step); } return builder; }
/** * Continue with this decider if the previous step was successful. Returns a flow builder and when the flow is ended * a job builder will be returned to continue the job configuration if needed. * * @param decider a decider to execute next * @return builder for fluent chaining */ public JobFlowBuilder next(JobExecutionDecider decider) { for (Step step : steps) { if (builder == null) { builder = new JobFlowBuilder(new FlowJobBuilder(this), step); } else { builder.next(step); } } if (builder == null) { builder = new JobFlowBuilder(new FlowJobBuilder(this), decider); } else { builder.next(decider); } return builder; }
public JobFlowBuilder(FlowJobBuilder parent, JobExecutionDecider decider) { super(parent.getName()); this.parent = parent; start(decider); }
/** * Start a job with this step, but expect to transition from there to other flows or steps. * * @param step the step to start with * @return a builder to enable fluent chaining */ public JobFlowBuilder start(Step step) { return new JobFlowBuilder(this, step); }
@Bean public Job conditionalJob(JobBuilderFactory jobs, Step conditionalStep1, Step conditionalStep2, Step conditionalStep3, Step conditionalStep4, Step conditionalStep5) throws Exception { return jobs.get("conditionalJob") .incrementer(new RunIdIncrementer()) .flow(conditionalStep1).on(ExitStatus.FAILED.getExitCode()).to(conditionalStep3) .from(conditionalStep1).on("HOGE").to(conditionalStep4) .from(conditionalStep1).on("*").to(conditionalStep2) .from(conditionalStep4).next(conditionalStep5).on("*").stop() .end() .build(); }
/** * Build a flow and inject it into the parent builder. The parent builder is then returned so it can be enhanced * before building an actual job. Normally called explicitly via {@link #end()}. * * @see org.springframework.batch.core.job.builder.FlowBuilder#build() */ @Override public FlowJobBuilder build() { Flow flow = flow(); parent.flow(flow); return parent; }
public Job build() { if (builder != null) { return builder.end().build(); } SimpleJob job = new SimpleJob(getName()); super.enhance(job); job.setSteps(steps); try { job.afterPropertiesSet(); } catch (Exception e) { throw new JobBuilderException(e); } return job; }