Search in sources :

Example 1 with CeQueueDao

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);
    }
}
Also used : DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto) CeQueueDto(org.sonar.db.ce.CeQueueDto) CeQueueDao(org.sonar.db.ce.CeQueueDao) CeTask(org.sonar.ce.task.CeTask)

Aggregations

CeTask (org.sonar.ce.task.CeTask)1 DbSession (org.sonar.db.DbSession)1 CeQueueDao (org.sonar.db.ce.CeQueueDao)1 CeQueueDto (org.sonar.db.ce.CeQueueDto)1 ComponentDto (org.sonar.db.component.ComponentDto)1