spring-batch icon indicating copy to clipboard operation
spring-batch copied to clipboard

Conditional Flow for steps does not work

Open vatsla20 opened this issue 2 years ago • 2 comments

Condition flow mention in the spring document not working as expected.

Environment spring-boot-starter-parent - 3.0.1 spring.batch.version - 5.0.0

As mentioned here I have used a similar approach to my job (https://docs.spring.io/spring-batch/docs/current/reference/html/step.html#conditionalFlow)

public Job exportJob() {
    return new JobBuilder(jobname, jobRepository)
        .incrementer(new RunIdIncrementer())
        .listener(jobListener)
        .start(step1("params"))
            .next(step2())
            .on("COMPLETED").to(step3())
            .from(step2()).on("COMPLETED").to(step4())
        .end()
        .build();
  }

I want the step4 to be executed on the failure of step2 and step3 on success. Currently whichever condition in mention in the 'on' statement that works fine but condition mention in 'from' statement is ignored and I get this error.

org.springframework.batch.core.JobExecutionException: Flow execution ended unexpectedly
	at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:143) ~[spring-batch-core-5.0.0.jar:5.0.0]
	at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:316) ~[spring-batch-core-5.0.0.jar:5.0.0]
	at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:157) ~[spring-batch-core-5.0.0.jar:5.0.0]
	at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) ~[spring-core-6.0.3.jar:6.0.3]
	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:148) ~[spring-batch-core-5.0.0.jar:5.0.0]
	at org.springframework.batch.core.launch.support.TaskExecutorJobLauncher.run(TaskExecutorJobLauncher.java:70) ~[spring-batch-core-5.0.0.jar:5.0.0]
Caused by: org.springframework.batch.core.job.flow.FlowExecutionException: Ended flow=ExportPipeline at state=ExportPipeline.step2 with exception
	at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:177) ~[spring-batch-core-5.0.0.jar:5.0.0]
	at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:142) ~[spring-batch-core-5.0.0.jar:5.0.0]
	at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:137) ~[spring-batch-core-5.0.0.jar:5.0.0]

Is this an issue with spring batch? Could I please get a solution for such a conditional scenario for the steps execution? Thanks in advance.

vatsla20 avatar Mar 16 '23 12:03 vatsla20