Files
outline/server/queues/tasks/CleanupPermanentlyDeletedDocumentsTask.ts
T
Tom Moor 5c938b0d1a Use retention period presets instead of arbitrary values
Replace free-form retention days with a fixed set of presets
(0, 7, 14, 30, 90, 180, 365) where 0 means infinite/never delete.
This bounds the number of cron sub-tasks and simplifies the system
by removing findUniquePreferenceValues in favor of iterating over
known presets directly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-29 17:30:46 -04:00

49 lines
1.3 KiB
TypeScript

import Logger from "@server/logging/Logger";
import { RetentionPeriodPresets } from "@shared/constants";
import { Minute } from "@shared/utils/time";
import { TaskPriority } from "./base/BaseTask";
import { CronTask, TaskInterval } from "./base/CronTask";
import type { Props } from "./base/CronTask";
import CleanupPermanentlyDeletedDocumentsByRetentionTask from "./CleanupPermanentlyDeletedDocumentsByRetentionTask";
export default class CleanupPermanentlyDeletedDocumentsTask extends CronTask {
/**
* Schedules a worker task for each retention period preset.
*
* @param props Properties to be used by the task.
*/
public async perform(props: Props) {
const task = new CleanupPermanentlyDeletedDocumentsByRetentionTask();
for (const days of RetentionPeriodPresets) {
if (days === 0) {
continue;
}
await task.schedule({
limit: props.limit,
retentionDays: days,
partition: props.partition,
});
}
Logger.debug(
"task",
`Scheduled ${RetentionPeriodPresets.length - 1} tranches for document cleanup`
);
}
public get options() {
return {
attempts: 1,
priority: TaskPriority.Background,
};
}
public get cron() {
return {
interval: TaskInterval.Hour,
partitionWindow: 15 * Minute.ms,
};
}
}