Skip to content

Add retry capabilities in when launching jobsΒ #5030

@fmbenhassine

Description

@fmbenhassine

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:

Metadata

Metadata

Assignees

Labels

in: corestatus: for-internal-teamIssues that are planned to be resolved by the Spring Batch team, and not open for contributions.type: feature

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions