public void run()

in src/main/java/com/ericsson/gerrit/plugins/highavailability/autoreindex/ReindexRunnable.java [46:87]


  public void run() {
    Optional<LocalDateTime> maybeIndexTs = indexTs.getUpdateTs(itemName);
    String itemNameString = itemName.name().toLowerCase();
    if (maybeIndexTs.isPresent()) {
      newLastIndexTs = maxTimestamp(newLastIndexTs, Timestamp.valueOf(maybeIndexTs.get()));
      log.atFine().log("Scanning for all the %ss after %s", itemNameString, newLastIndexTs);
      try (ManualRequestContext mctx = ctx.open()) {
        int count = 0;
        int errors = 0;
        Stopwatch stopwatch = Stopwatch.createStarted();
        for (T c : fetchItems()) {
          try {
            Optional<Timestamp> itemTs = indexIfNeeded(c, newLastIndexTs);
            if (itemTs.isPresent()) {
              count++;
              newLastIndexTs = maxTimestamp(newLastIndexTs, itemTs.get());
            }
          } catch (Exception e) {
            log.atSevere().withCause(e).log("Unable to reindex %s %s", itemNameString, c);
            errors++;
          }
        }
        long elapsedNanos = stopwatch.stop().elapsed(TimeUnit.NANOSECONDS);
        if (count > 0) {
          log.atInfo().log(
              "%d %ss reindexed in %d msec (%d/sec), %d failed",
              count,
              itemNameString,
              elapsedNanos / 1000000L,
              (count * 1000L) / (elapsedNanos / 1000000L),
              errors);
        } else if (errors > 0) {
          log.atInfo().log("%d %ss failed to reindex", errors, itemNameString);
        } else {
          log.atFine().log("Scanning finished");
        }
        indexTs.update(itemName, newLastIndexTs.toLocalDateTime());
      } catch (Exception e) {
        log.atSevere().withCause(e).log("Unable to scan %ss", itemNameString);
      }
    }
  }