Skip to content

Conditional Flow for steps does not work  #4328

Open
@vatsla20

Description

@vatsla20

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions