我的工作,我已经使用了Spring Batch的应用RetryTemplate有SimpleRetryPolicy。
在此应用程序中,ItemProcessor通常需要30-35分钟才能完成特定任务。但是有时候,完成同一任务需要不到2个小时。
ItemProcessor如果分配的任务在给定时间内未完成,是否可以重试我的方法?
我正在寻找一些Java / Spring内置功能,而不是编写自己的超时逻辑。
spring spring-batch spring-retry retrypolicy spring-batch-job-monitoring
我遵循了spring 批处理文档,但无法异步运行我的工作。
所以我从 web 容器运行作业,作业将通过 REST 端点触发。
我想在完成整个工作之前获得 JobInstance ID以作为响应传递它。因此,他们可以稍后使用 JobInstance ID 检查作业的状态,而无需等待。但我无法让它工作。下面是我试过的示例代码。请让我知道我错过了什么或错了什么。
BatchConfig 使 Async JobLauncher
@Configuration
public class BatchConfig {
@Autowired
JobRepository jobRepository;
@Bean
public JobLauncher simpleJobLauncher() throws Exception {
SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
jobLauncher.setJobRepository(jobRepository);
jobLauncher.setTaskExecutor(new SimpleAsyncTaskExecutor());
jobLauncher.afterPropertiesSet();
return jobLauncher;
}
}
Run Code Online (Sandbox Code Playgroud)
控制器
@Autowired
JobLauncher jobLauncher;
@RequestMapping(value="/trigger-job", method = RequestMethod.GET)
public Long workHard() throws Exception {
JobParameters jobParameters = new JobParametersBuilder().
addLong("time", System.currentTimeMillis())
.toJobParameters();
JobExecution jobExecution = jobLauncher.run(batchComponent.customJob("paramhere"), jobParameters);
System.out.println(jobExecution.getJobInstance().getInstanceId());
System.out.println("OK RESPONSE"); …Run Code Online (Sandbox Code Playgroud) java spring spring-batch spring-boot spring-batch-job-monitoring
spring ×2
spring-batch ×2
spring-batch-job-monitoring ×2
java ×1
retrypolicy ×1
spring-boot ×1
spring-retry ×1