user518066
user518066

Reputation: 1437

Spring batch retry failed step

In Spring Batch, I would like to retry 2 (related) steps when one step fails. I have a java dsl job that consists of a Job, Steps and Tasklets. The tasklets (non-chunk) just invoke independent actions - db and jms, and NO file processing.

For simplicity:

jobBuilders.get("WorkFlow")
                .flow(stepsA.step1())
                .next(stepsA.step2())
                .next(stepsB.step3())
                .next(stepsB.step4())
                .end()
                .build();

So the job runs steps workflow in a sequential order. If stepsB.step4 fails and throws an exception and step4 has a status of FAILED. Is there a way to auto retry BOTH steps stepsB.step3 and stepsB.step4 in this scenario, using a StepListener or Decider. Is this possible?

An alternative would be to put StepB step3 and step4 logic into one step which calls a service that is retryable (retryTemplate).

Please advise

Upvotes: 0

Views: 715

Answers (1)

Mahmoud Ben Hassine
Mahmoud Ben Hassine

Reputation: 31745

is there a way to auto retry BOTH steps

The is no way to auto retry steps in Spring Batch. It is up to you to design the flow to retry (loop?) on a given step until it succeeds.

The alternative you suggest is a better option IMO as it is easier to configure and think about.

Upvotes: 1

Related Questions