I am trying to set and retrieve progress information for a currently running spring batch tasklet.
I have a simple spring batch job based on one step, eg.
public Step jobStep() {
return stepBuilderFactory.get(JOB_STEP_1)
.tasklet((contribution, chunkContext) -> {
...
}).build();
}
The tasklet is a simple loop doing some stuff, which may take a lot of time.
After every iteration in the loop, I am setting some progress information in the JobExecutionContext eg.
chunkContext.getStepContext().getStepExecution().getJobExecution().getExecutionContext().put("myJobStatus", "10 of 100 finished");
From another thread (e.g. a rest service) I want to check the progress of the actual tasklet, im using the JobExplorer for this
String status = (String)jobExplorer.getJobExecution(jobId).getExecutionContext().get("myJobStatus");
Unfortunately the myJobStatus property is only set when the step or the job is finished. I even tried to replace the simple loop with a loop of steps, but with the same result.
Is there another way to set and access progress information for currently running jobs?
I'm using the DefaultBatchConfigurer with a JDBC based JobRepository etc.