@Override
    public int logicalDeleteForDeletedProcessorFilters(final Instant deleteThreshold) {
        final List<Integer> result =
                JooqUtil.contextResult(processorDbConnProvider, context -> context
                        .select(PROCESSOR_FILTER.ID)
                        .from(PROCESSOR_FILTER)
                        .where(PROCESSOR_FILTER.DELETED.eq(true))
                        .and(PROCESSOR_FILTER.UPDATE_TIME_MS.lessThan(deleteThreshold.toEpochMilli()))
                        .fetch(PROCESSOR_FILTER.ID));

        LOGGER.debug(() ->
                LogUtil.message("Found {} logically deleted filters with an update time older than {}",
                        result.size(), deleteThreshold));

        final AtomicInteger totalCount = new AtomicInteger();
        // Delete one by one.
        result.forEach(processorFilterId -> {
            try {
                final int count = JooqUtil.withDeadlockRetries(() ->
                                JooqUtil.contextResult(processorDbConnProvider, context -> context
                                        .update(PROCESSOR_TASK)
                                        .set(PROCESSOR_TASK.STATUS, TaskStatus.DELETED.getPrimitiveValue())
                                        .set(PROCESSOR_TASK.VERSION, PROCESSOR_TASK.VERSION.plus(1))
                                        .set(PROCESSOR_TASK.STATUS_TIME_MS, Instant.now().toEpochMilli())
                                        .where(PROCESSOR_TASK.FK_PROCESSOR_FILTER_ID.eq(processorFilterId))
                                        .and(PROCESSOR_TASK.STATUS.notEqual(TaskStatus.DELETED.getPrimitiveValue()))
                                        .execute()),
                        () -> "Logically delete processor tasks for processorFilterId {}");

                LOGGER.debug("Logically deleted {} processor tasks for processorFilterId {}", count, processorFilterId);
                totalCount.addAndGet(count);
            } catch (final DataAccessException e) {
                if (e.getCause() instanceof final SQLIntegrityConstraintViolationException sqlEx) {
                    LOGGER.debug("Expected constraint violation exception: " + sqlEx.getMessage(), e);
                } else {
                    throw e;
                }
            }
        });
        LOGGER.debug(() -> "logicalDeleteForDeletedProcessorFilters returning: " + totalCount.get());

        return totalCount.get();
    }
Logically delete tasks that are associated with filters that have been logically deleted for longer than the
threshold.

@param deleteThreshold Only logically delete tasks with an update time older than the threshold.
@return The number of logically deleted tasks.
stroom-processor/stroom-processor-impl-db/src/main/java/stroom/processor/impl/db/ProcessorTaskDaoImpl.java