Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Batch javaConfig: Conditional Flow

Is there any suggestions to the way to transfrom this xml config to javaconfig:

<job id="job">
    <step id="step1" >
        <next on="FAILED" to="step2"/>
        <next on="*" to="step3"/> 
    </step>
    <step id="step2"/>
    <step id="step3"next="step4"/>
    <step id="step4"/>
</job>  

I was able to create a job having one step leading to another step on success and to a different one on failure:

SimpleJobBuilder builder = new JobBuilder("job").repository(jobRepository)
.start(step1()).next(step2())
.on("FAILED").to(step3()).build();  
like image 568
user3469745 Avatar asked Mar 27 '14 17:03

user3469745


1 Answers

Maybe like this:

jobs.get("job")
    .start(step1())
        .on("FAILED").to(step2())
        .next(step3())
    .from(step1())
        .next(step3())
        .next(step4())
.build().build();

(Step 2 is only executed if step 1 finished with status 'FAILED'. All other steps are executed in order. Is that what you intended?)

like image 76
Dave Syer Avatar answered Sep 27 '22 19:09

Dave Syer