@Override
  public void run() {
    try (DbSession dbSession = dbClient.openSession(false)) {
      List<CeActivityDto> recentSuccessfulTasks = getRecentSuccessfulTasks(dbSession);

      Collection<String> entityUuids = recentSuccessfulTasks.stream()
        .map(CeActivityDto::getEntityUuid)
        .toList();
      List<EntityDto> entities = dbClient.entityDao().selectByUuids(dbSession, entityUuids);
      Map<String, String> entityUuidAndKeys = entities.stream()
        .collect(Collectors.toMap(EntityDto::getUuid, EntityDto::getKey));

      reportObservedDurationForTasks(recentSuccessfulTasks, entityUuidAndKeys);
    }
    lastUpdatedTimestamp = system.now();
  }
@Test
  public void run_given5SuccessfulTasks_observeDurationFor5Tasks() {
    RecentTasksDurationTask task = new RecentTasksDurationTask(dbClient, metrics, config, system);
    List<CeActivityDto> recentTasks = createTasks(5, 0);

    when(entityDao.selectByUuids(any(), any())).thenReturn(createEntityDtos(5));
    when(ceActivityDao.selectNewerThan(any(), anyLong())).thenReturn(recentTasks);

    task.run();

    verify(metrics, times(5)).observeComputeEngineTaskDuration(anyLong(), any(), any());
  }