@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(); }
/** * Create a new job builder that will execute a step or sequence of steps. * * @param step a step to execute * @return a {@link SimpleJobBuilder} */ public JobFlowBuilder flow(Step step) { return new FlowJobBuilder(this).start(step); } }
/** * 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; }
@Test public void testBuildOnOneLine() throws Exception { FlowJobBuilder builder = new JobBuilder("flow").repository(jobRepository).start(step1).on("COMPLETED") .to(step2).end().preventRestart(); builder.build().execute(execution); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); assertEquals(2, execution.getStepExecutions().size()); }
@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(); }
public JobFlowBuilder(FlowJobBuilder parent) { super(parent.getName()); this.parent = parent; }
/** * @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); }
@Test public void testBuildOverTwoLines() throws Exception { FlowJobBuilder builder = new JobBuilder("flow").repository(jobRepository).start(step1).on("COMPLETED") .to(step2).end(); builder.preventRestart(); builder.build().execute(execution); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); assertEquals(2, execution.getStepExecutions().size()); }
public JobFlowBuilder(FlowJobBuilder parent, Step step) { super(parent.getName()); this.parent = parent; start(step); }
/** * 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 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; }
@Test public void testBuildSingleFlow() throws Exception { Flow flow = new FlowBuilder<Flow>("subflow").from(step1).next(step2).build(); FlowJobBuilder builder = new JobBuilder("flow").repository(jobRepository).start(flow).end().preventRestart(); builder.build().execute(execution); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); assertEquals(2, execution.getStepExecutions().size()); }
/** * Create a new job builder that will execute a flow. * * @param flow a flow to execute * @return a {@link SimpleJobBuilder} */ public JobFlowBuilder start(Flow flow) { return new FlowJobBuilder(this).start(flow); }
public JobFlowBuilder(FlowJobBuilder parent, Flow flow) { super(parent.getName()); this.parent = parent; start(flow); }
/** * 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); }
/** * 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; }
@Bean public Job importUserJob(JobBuilderFactory jobs, Step s1, JobExecutionListener listener) { return jobs.get("importUserJob") .incrementer(new RunIdIncrementer()) .listener(listener) .flow(s1) .end() .build(); }
@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()); }
/** * Create a new job builder that will execute a flow. * * @param flow a flow to execute * @return a {@link SimpleJobBuilder} */ public JobFlowBuilder start(Flow flow) { return new FlowJobBuilder(this).start(flow); }