Access JobParameters via JobInstance #5086
-
|
Currently, I am trying to implement some logic that tries to find out which This is how I do it at the moment: private @NonNull Set<JobInstance> getIncompleteLegacyParameterValueJobInstances() {
try {
final var jobInstanceCount = jobExplorer.getJobInstanceCount(LegacyParameterValueJobConfig.JOB_NAME);
final var pageSize = 5;
final var pageCount = (long) Math.ceil((double) jobInstanceCount / pageSize);
var explorerIndex = 0;
final var jobInstances = new HashSet<JobInstance>();
for (int pageIndex = 1; pageIndex <= pageCount; pageIndex++) {
jobInstances.addAll(jobExplorer.getJobInstances(LegacyParameterValueJobConfig.JOB_NAME, explorerIndex, pageSize));
explorerIndex += pageSize;
}
return jobInstances
.stream()
.filter(instance -> {
final var latestExecution = jobExplorer.getLastJobExecution(instance);
// TODO: get JobParameters and make this method return a custom value object with JobInstance and JobParameters
// TODO: what about job executions with state UNKNOWN? Wait for spring batch 6 or do manual recovery?
return (
latestExecution == null ||
(latestExecution.getExitStatus().equals(ExitStatus.FAILED) || latestExecution.getExitStatus().equals(ExitStatus.STOPPED))
);
})
.collect(Collectors.toSet());
} catch (NoSuchJobException noSuchJobException) {
throw new IllegalStateException("No known job with name " + LegacyParameterValueJobConfig.JOB_NAME, noSuchJobException);
}
}The first TODO already summarizes my problem/questions: Why can't I access the As far as I know, a Currently, to get the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
That's correct. All job executions of a given job instance have the same identifying job parameters, but can have different non-identifying parameters. That's why there is no job parameters attached to a given instance, you need to get at least one of the executions and extract identifying job parameters for it.
It is not possible to restart a job execution in an "UNKNOWN" status, even with Spring Batch 6 (see Does that answer your questions? |
Beta Was this translation helpful? Give feedback.
That's correct. All job executions of a given job instance have the same identifying job parameters, but can have different non-identifying parameters. That's why there is no job parameters attached to a given instance, you need to get at least one of the executions and extract identifying job parameters for it.
It is not possible to restart a job execution in an "UNKNOWN" status, even with Spring Batch 6 (see
spring-batch/spring-batch-core/src/main/java/org/springframework…