use of org.sonar.ce.queue.CeTaskSubmit in project sonarqube by SonarSource.
the class AsyncIssueIndexingImpl method triggerOnIndexCreation.
@Override
public void triggerOnIndexCreation() {
try (DbSession dbSession = dbClient.openSession(false)) {
// remove already existing indexation task, if any
removeExistingIndexationTasks(dbSession);
dbClient.branchDao().updateAllNeedIssueSync(dbSession);
List<BranchDto> branchInNeedOfIssueSync = dbClient.branchDao().selectBranchNeedingIssueSync(dbSession);
LOG.info("{} branch found in need of issue sync.", branchInNeedOfIssueSync.size());
if (branchInNeedOfIssueSync.isEmpty()) {
return;
}
List<String> projectUuids = branchInNeedOfIssueSync.stream().map(BranchDto::getProjectUuid).distinct().collect(Collectors.toList());
LOG.info("{} projects found in need of issue sync.", projectUuids.size());
sortProjectUuids(dbSession, projectUuids);
Map<String, List<BranchDto>> branchesByProject = branchInNeedOfIssueSync.stream().collect(Collectors.groupingBy(BranchDto::getProjectUuid));
List<CeTaskSubmit> tasks = new ArrayList<>();
for (String projectUuid : projectUuids) {
List<BranchDto> branches = branchesByProject.get(projectUuid);
for (BranchDto branch : branches) {
tasks.add(buildTaskSubmit(branch));
}
}
ceQueue.massSubmit(tasks);
dbSession.commit();
}
}
Aggregations