Files
outline/plugins/webhooks/server/tasks/CleanupWebhookDeliveriesTask.ts
Tom Moor 42959d66db chore: Add cron task partitioning (#10736)
* wip

* Implementation complete

* tidying

* test

* Address feedback

* Remove duplicative retry logic from UpdateDocumentsPopularityScoreTask.
Now that we're split across many runs this is not neccessary

* Refactor to subclass, config to instance

* Refactor BaseTask to named export

* fix: Missing partition

* tsc

* Feedback
2025-11-27 16:57:52 +01:00

41 lines
1.1 KiB
TypeScript

import { subDays } from "date-fns";
import { Op } from "sequelize";
import Logger from "@server/logging/Logger";
import { WebhookDelivery } from "@server/models";
import { TaskPriority } from "@server/queues/tasks/base/BaseTask";
import {
CronTask,
TaskInterval,
Props,
} from "@server/queues/tasks/base/CronTask";
import { Hour } from "@shared/utils/time";
export default class CleanupWebhookDeliveriesTask extends CronTask {
public async perform({ partition }: Props) {
Logger.info("task", `Deleting WebhookDeliveries older than one week…`);
const count = await WebhookDelivery.unscoped().destroy({
where: {
createdAt: {
[Op.lt]: subDays(new Date(), 7),
},
...this.getPartitionWhereClause("id", partition),
},
});
Logger.info("task", `${count} old WebhookDeliveries deleted.`);
}
public get cron() {
return {
interval: TaskInterval.Day,
partitionWindow: Hour.ms,
};
}
public get options() {
return {
attempts: 1,
priority: TaskPriority.Background,
};
}
}