class PreparationStepMarker implements StepMarker {

    @Override
    public Result mark(PreparationRepository repository, UUID marker) {
        if (repository.exist(Preparation.class, recentlyModified())) {
            LOGGER.info("Not running clean up (at least a preparation modified within last hour).");
            logRecentlyModified(repository);
            return Result.INTERRUPTED;
        }

        final AtomicBoolean interrupted = new AtomicBoolean(false);
        repository
                .list(Preparation.class) //
                .filter(p -> !interrupted.get()) //
                .forEach(p -> {
                    if (repository.exist(Preparation.class, recentlyModified())) {
                        LOGGER.info("Interrupting clean up (preparation modified within last hour).");
                        logRecentlyModified(repository);
                        interrupted.set(true);
                        return;
                    }
                    final Collection<Identifiable> markedSteps = p
                            .getSteps() //
                            .stream() //
                            .filter(s -> !Objects.equals(s, Step.ROOT_STEP))
                            .peek(s -> s.setMarker(marker.toString())) //
                            .collect(Collectors.toList());
                    repository.add(markedSteps);
                });
        return interrupted.get() ? Result.INTERRUPTED : Result.COMPLETED;
    }

}