@Override public long getPendingCount() { try (DbSession dbSession = dbClient.openSession(false)) { return dbClient.ceQueueDao().countByStatus(dbSession, CeQueueDto.Status.PENDING); } }
@Override public WorkersPauseStatus getWorkersPauseStatus() { try (DbSession dbSession = dbClient.openSession(false)) { Optional<String> propValue = dbClient.internalPropertiesDao().selectByKey(dbSession, InternalProperties.COMPUTE_ENGINE_PAUSE); if (!propValue.isPresent() || !propValue.get().equals("true")) { return WorkersPauseStatus.RESUMED; } int countInProgress = dbClient.ceQueueDao().countByStatus(dbSession, IN_PROGRESS); if (countInProgress > 0) { return WorkersPauseStatus.PAUSING; } return WorkersPauseStatus.PAUSED; } }
@Test public void count_Pending_from_database() { when(getDbClient().ceQueueDao().countByStatus(any(), eq(CeQueueDto.Status.PENDING))).thenReturn(42); assertThat(underTest.getPendingCount()).isEqualTo(42); } }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("Compute Engine Tasks"); try (DbSession dbSession = dbClient.openSession(false)) { setAttribute(protobuf, "Total Pending", dbClient.ceQueueDao().countByStatus(dbSession, CeQueueDto.Status.PENDING)); setAttribute(protobuf, "Total In Progress", dbClient.ceQueueDao().countByStatus(dbSession, CeQueueDto.Status.IN_PROGRESS)); setAttribute(protobuf, "Max Workers per Node", workerCountProvider == null ? DEFAULT_NB_OF_WORKERS : workerCountProvider.get()); setAttribute(protobuf, "Workers Paused", "true".equals(dbClient.internalPropertiesDao().selectByKey(dbSession, InternalProperties.COMPUTE_ENGINE_PAUSE).orElse(null))); } return protobuf.build(); } }
@Test public void test_queue_state_with_default_settings() { when(dbClient.ceQueueDao().countByStatus(any(), eq(CeQueueDto.Status.PENDING))).thenReturn(10); when(dbClient.ceQueueDao().countByStatus(any(), eq(CeQueueDto.Status.IN_PROGRESS))).thenReturn(1); CeQueueGlobalSection underTest = new CeQueueGlobalSection(dbClient); ProtobufSystemInfo.Section section = underTest.toProtobuf(); assertThatAttributeIs(section, "Total Pending", 10); assertThatAttributeIs(section, "Total In Progress", 1); assertThatAttributeIs(section, "Max Workers per Node", 1); }
@Test public void test_queue_state_with_overridden_settings() { when(dbClient.ceQueueDao().countByStatus(any(), eq(CeQueueDto.Status.PENDING))).thenReturn(10); when(dbClient.ceQueueDao().countByStatus(any(), eq(CeQueueDto.Status.IN_PROGRESS))).thenReturn(2); when(workerCountProvider.get()).thenReturn(5); CeQueueGlobalSection underTest = new CeQueueGlobalSection(dbClient, workerCountProvider); ProtobufSystemInfo.Section section = underTest.toProtobuf(); assertThatAttributeIs(section, "Total Pending", 10); assertThatAttributeIs(section, "Total In Progress", 2); assertThatAttributeIs(section, "Max Workers per Node", 5); }
@Test public void start_does_not_reset_in_progress_tasks_to_pending() { insertInQueue("TASK_1", CeQueueDto.Status.PENDING); insertInQueue("TASK_2", CeQueueDto.Status.IN_PROGRESS); runCleaner(); assertThat(dbTester.getDbClient().ceQueueDao().countByStatus(dbTester.getSession(), CeQueueDto.Status.PENDING)).isEqualTo(1); assertThat(dbTester.getDbClient().ceQueueDao().countByStatus(dbTester.getSession(), CeQueueDto.Status.IN_PROGRESS)).isEqualTo(1); }
@Override public long getPendingCount() { try (DbSession dbSession = dbClient.openSession(false)) { return dbClient.ceQueueDao().countByStatus(dbSession, CeQueueDto.Status.PENDING); } }
@Override public WorkersPauseStatus getWorkersPauseStatus() { try (DbSession dbSession = dbClient.openSession(false)) { java.util.Optional<String> propValue = dbClient.internalPropertiesDao().selectByKey(dbSession, InternalProperties.COMPUTE_ENGINE_PAUSE); if (!propValue.isPresent() || !propValue.get().equals("true")) { return WorkersPauseStatus.RESUMED; } int countInProgress = dbClient.ceQueueDao().countByStatus(dbSession, CeQueueDto.Status.IN_PROGRESS); if (countInProgress > 0) { return WorkersPauseStatus.PAUSING; } return WorkersPauseStatus.PAUSED; } }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("Compute Engine Tasks"); try (DbSession dbSession = dbClient.openSession(false)) { setAttribute(protobuf, "Total Pending", dbClient.ceQueueDao().countByStatus(dbSession, CeQueueDto.Status.PENDING)); setAttribute(protobuf, "Total In Progress", dbClient.ceQueueDao().countByStatus(dbSession, CeQueueDto.Status.IN_PROGRESS)); setAttribute(protobuf, "Max Workers per Node", workerCountProvider == null ? DEFAULT_NB_OF_WORKERS : workerCountProvider.get()); setAttribute(protobuf, "Workers Paused", "true".equals(dbClient.internalPropertiesDao().selectByKey(dbSession, InternalProperties.COMPUTE_ENGINE_PAUSE).orElse(null))); } return protobuf.build(); } }