/** * 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); }
@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()); }
@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()); }
/** * 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); }
/** * 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); }
/** * 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); }
@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(); }