fix race condition

This commit is contained in:
Ken Stevens 2021-12-02 01:14:17 -05:00
parent 1a1243db34
commit 3e7eec4e9e
1 changed files with 12 additions and 3 deletions

View File

@ -62,10 +62,11 @@ public class BatchJobHelper {
public List<JobExecution> awaitAllBulkJobCompletions(boolean theFailIfNotJobsFound, String... theJobNames) {
assert theJobNames.length > 0;
List<JobInstance> matchingJobInstances = new ArrayList<>();
for (String nextName : theJobNames) {
matchingJobInstances.addAll(myJobExplorer.findJobInstancesByJobName(nextName, 0, 100));
if (theFailIfNotJobsFound) {
await().until(() -> !getJobInstances(theJobNames).isEmpty());
}
List<JobInstance> matchingJobInstances = getJobInstances(theJobNames);
if (theFailIfNotJobsFound) {
if (matchingJobInstances.isEmpty()) {
List<String> wantNames = Arrays.asList(theJobNames);
@ -81,6 +82,14 @@ public class BatchJobHelper {
return matchingExecutions;
}
private List<JobInstance> getJobInstances(String[] theJobNames) {
List<JobInstance> matchingJobInstances = new ArrayList<>();
for (String nextName : theJobNames) {
matchingJobInstances.addAll(myJobExplorer.findJobInstancesByJobName(nextName, 0, 100));
}
return matchingJobInstances;
}
public JobExecution awaitJobExecution(Long theJobExecutionId) {
JobExecution jobExecution = myJobExplorer.getJobExecution(theJobExecutionId);
awaitJobCompletion(jobExecution);