class ValidationRunCleanupService {

    public Pair<AtomicInteger, AtomicInteger> cleanupValidationRuns() {
        AtomicInteger oldCount = new AtomicInteger();
        AtomicInteger orphanCount = new AtomicInteger();
        InstantWithoutNanos completedBefore = InstantWithoutNanos.now().minus(cleanupGraceDuration);
        Long t = Time.timed(() -> {
            // Delete all validation runs older than `cleanupGraceDuration` that have a later validation run.
            oldCount.set(storage.writeTx(tx -> validationRuns.removeOldValidationRuns(tx, completedBefore)));
            orphanCount.set(storage.writeTx(tx -> validationRuns.removeOrphanValidationRunAssociations(tx)));
        });
        log.info("Removed {} old validation runs and {} orphans in {}ms", oldCount.get(), orphanCount.get(), t);
        storage.gc();
        return Pair.of(oldCount, orphanCount);
    }

    public  ValidationRunCleanupService(@Value("${rpki.validator.validation.run.cleanup.grace.duration}") String cleanupGraceDuration,
                                       Storage storage);

}