I've written a Spring Boot Application where I've enabled Spring Batch Scheduling and Retriable as follow:
@SpringBootApplication
@EnableBatchProcessing
@EnableScheduling
@EnableRetry
public class FilldashboardApp {
}
I've defined a controller as follow:
@Component
public class JobRunnerStats {
@Scheduled(cron = "0 0/2 * ? * *")
@Retryable(maxAttempts = 10, backoff = @Backoff(delay = 1000))
protected JobExecution runJob() throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException {
JobParameters jobParameters = null;
if (this.jobParameters == null) {
jobParameters = buildJobParameters(null);
} else {
jobParameters = this.jobParameters;
this.jobParameters = null;
}
return simpleJobLauncher.run(this.jobStats, jobParameters);
}
}
After 2 minutes, as the cron expression specified starts the job, so in the first step of it I'll send it in exception so in the job execution and step I've tracked the FAILED
status.
So, as the @Retryable annotation explains, I'm waiting to recall the job after 1 second (delay = 1000 microseconds) but the next access in the method is after 2 minutes (so, when the cron expression has matched)
I don't know where my fault
CodePudding user response:
Check out this issue on Spring Retry. Most likely the problem you are experiencing is a Spring bug (SPR-16196) fixed only in versions 4.3.14, 5.0.3 I tried your snippet without using Spring Batch and it works fine.
@Component
public class TestComponent {
Logger logger = LoggerFactory.getLogger(TestApplication.class);
@Retryable(maxAttempts = 10, backoff = @Backoff(delay = 1000))
@Scheduled(cron = "0 0/2 * ? * *")
public void foo() {
logger.info("foo");
throw new RuntimeException("runtime");
}
}
CodePudding user response:
Have you tried to include all expected exceptions as retryable param?
@Retryable(maxAttempts = 10, backoff = @Backoff(delay = 1000),value={JobExecutionAlreadyRunningException.class})
I read a few tutorials and I'm not sure how retryable behaves when no exception (expected) were specified