@Override
    public List<ExistingCreatedTask> findExistingCreatedTasks(final long lastTaskId,
                                                              final int filterId,
                                                              final int limit) {
        final Result<Record2<Long, Long>> records = JooqUtil.contextResult(processorDbConnProvider, context ->
                context
                        .select(PROCESSOR_TASK.ID, PROCESSOR_TASK.META_ID)
                        .from(PROCESSOR_TASK)
                        .where(PROCESSOR_TASK.ID.gt(lastTaskId))
                        .and(PROCESSOR_TASK.STATUS.eq(TaskStatus.CREATED.getPrimitiveValue()))
                        .and(PROCESSOR_TASK.FK_PROCESSOR_FILTER_ID.eq(filterId))
                        .orderBy(PROCESSOR_TASK.ID)
                        .limit(limit)
                        .fetch());
        return records.map(r -> new ExistingCreatedTask(r.value1(), r.value2()));
    }
Physically delete tasks that are logically deleted or complete for longer than the threshold.

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