use of org.sonar.db.ce.CeQueueDao in project sonarqube by SonarSource.
the class InternalCeQueueImpl method peek.
@Override
public Optional<CeTask> peek(String workerUuid, boolean excludeIndexationJob) {
requireNonNull(workerUuid, "workerUuid can't be null");
if (computeEngineStatus.getStatus() != ComputeEngineStatus.Status.STARTED || getWorkersPauseStatus() != WorkersPauseStatus.RESUMED) {
return Optional.empty();
}
try (DbSession dbSession = dbClient.openSession(false)) {
CeQueueDao ceQueueDao = dbClient.ceQueueDao();
int i = ceQueueDao.resetToPendingForWorker(dbSession, workerUuid);
if (i > 0) {
dbSession.commit();
LOG.debug("{} in progress tasks reset for worker uuid {}", i, workerUuid);
}
Optional<CeQueueDto> opt = findPendingTask(workerUuid, dbSession, ceQueueDao, excludeIndexationJob);
if (!opt.isPresent()) {
return Optional.empty();
}
CeQueueDto taskDto = opt.get();
Map<String, ComponentDto> componentsByUuid = loadComponentDtos(dbSession, taskDto);
Map<String, String> characteristics = dbClient.ceTaskCharacteristicsDao().selectByTaskUuids(dbSession, singletonList(taskDto.getUuid())).stream().collect(uniqueIndex(CeTaskCharacteristicDto::getKey, CeTaskCharacteristicDto::getValue));
CeTask task = convertToTask(dbSession, taskDto, characteristics, ofNullable(taskDto.getComponentUuid()).map(componentsByUuid::get).orElse(null), ofNullable(taskDto.getMainComponentUuid()).map(componentsByUuid::get).orElse(null));
queueStatus.addInProgress();
return Optional.of(task);
}
}
Aggregations