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