-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
There are several cases where launching a job might fail because of a transient error (like a database that is not ready yet, or a required service that is temporarily not available). I particularly think of cloud environments where services are deployed independently in no particular order so the batch job could be started before the database or other required resources are not ready yet. In these cases, it is unfortunate to not be able to retry launching the job (and therefore miss/waste a scheduled job launch cycle for example).
This feature is about adding the ability to retry the job launching sequence to the Job Operator API with a configurable retry template, something like:
@Configuration
@EnableBatchProcessing(retryTemplateRef = "batchRetryTemplate")
public class JobConfiguration {
@Bean
public Job job(JobRepository jobRepository) {
return new JobBuilder("job", jobRepository)
// define job execution flow
.build();
}
@Bean
public RetryTemplate batchRetryTemplate() {
RetryPolicy retryPolicy = RetryPolicy.builder()
.maxAttempts(3)
.delay(Duration.ofSeconds(1))
.includes(DataSourceLookupFailureException.class)
.build();
return new RetryTemplate(retryPolicy);
}
}This would retry to launch the job according to the defined retry policy when a DataSourceLookupFailureException.class is thrown at startup.
References: