Spring batch: Retry job if does not complete in particular time
Asked Answered
A

1

5

I am working on a Spring batch application where I have used RetryTemplate with SimpleRetryPolicy.

In this application, ItemProcessor usually takes 30-35 mins to complete a particular task. But sometimes, it takes from than 2hrs to complete that same task.

Is there a way to retry my ItemProcessor, if the assigned task is not completed within given time period?

I am looking for some Java/Spring in-build functionality instead of writing my own timeout logic.

Allard answered 30/4, 2018 at 10:43 Comment(8)
How are you stopping it when it goes over the time limit?Proteolysis
@MichaelMinella Currently, it keeps on going until job gets finished. So the job completion is the limit right now.Allard
Do you want to stop the job at the 35 minute mark or just rerun it again and let the first instance complete?Proteolysis
I want to Retry the same job with an TimedOut Exception.Allard
@SachinMhetre, Something like this probably? github.com/eziztm/batch_example/blob/…Exegetics
@TarunLalwani, I guess this shows the time interval between retries. I am looking for TimedOut exception kind of stuff. i.e. if job is not completed in given time, then exception should be thrownAllard
The only other info I found was this forum.spring.io/forum/spring-projects/batch/…, see if you can implement what it saysExegetics
So, what you're trying to do is to set a max timeout, right?Vanegas
V
6

You can define transactional-attributes to a given step. (https://docs.spring.io/spring-batch/trunk/reference/htmlsingle/#transactionAttributes)

Transaction attributes can be used to control the isolation, propagation, and timeout settings.

<step id="step1">
  <tasklet>
      <chunk reader="itemReader" writer="itemWriter" commit-interval="2"/>
      <transaction-attributes isolation="DEFAULT"
                              propagation="REQUIRED"
                              timeout="30"/>
  </tasklet>
</step>

If you're using Java configuration check https://mcmap.net/q/2036373/-spring-batch-java-config-transaction-attributes-equivalent.

Vanegas answered 3/5, 2018 at 9:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.