I've been trying to solve this issue for few days and I couldn't make it. I'm quite new with Spring 4, so maybe someone with experience can tell me how to do it.
I was trying to learn how to code a Spring Batch with the latest version of the framework. I followed the Getting Started Tutorial: https://spring.io/guides/gs/batch-processing/
Once the job was executing, I wanted to make it execute periodically. Therefore, I went for a scheduled task: https://spring.io/guides/gs/scheduling-tasks/
It looked easy to put both ideas together. In practise, it was not possible. I read a little bit and I added some code to make the jobExecution unique every time. Still, the coded step, once finished, never executes again.
I investigated a little bit and I've read about RepeatTemplate, but I don't see it clear how to make it fit with my code. Here you have the 3 relevant methods for the execution:
@Scheduled(cron="0 0/2 * * * ?")
public void run() throws Exception {
System.out.println("Job Started at :" + new Date());
JobParameters param = new JobParametersBuilder().addString("newsSyncJob",
String.valueOf(System.currentTimeMillis())).toJobParameters();
NewsJobCompletionListener listener = new NewsJobCompletionListener();
JobExecution execution = jobLauncher.run(newsSyncJob(listener), param);
System.out.println("Job finished with status :" + execution.getStatus());
}
/**
* Execution of the job
* @param listener
* @return
*/
@Bean
public Job newsSyncJob(NewsJobCompletionListener listener) {
log.debug("newsSyncJob execution started");
this.init();
return jobBuilderFactory.get("newsSyncJob")
.incrementer(new RunIdIncrementer())
.listener(listener)
.flow(step1())
.end()
.build();
}
@Bean
protected Step step1() {
return stepBuilderFactory.get("step1")
.<NewsSync, NewsSync> chunk(4)
.reader(filesReader()).
processor(newsProcessor()).
writer(stateWriter()).
build();
}
Any ideas how to make the step reexecute successfully? Thank you in advance!