Files
outline/server/queues/tasks/CleanupExpiredAttachmentsTask.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

35 lines
925 B
TypeScript

import { Op } from "sequelize";
import Logger from "@server/logging/Logger";
import { Attachment } from "@server/models";
import { TaskPriority } from "./base/BaseTask";
import { CronTask, Props, TaskInterval } from "./base/CronTask";
export default class CleanupExpiredAttachmentsTask extends CronTask {
public async perform({ limit }: Props) {
Logger.info("task", `Deleting expired attachments…`);
const attachments = await Attachment.unscoped().findAll({
where: {
expiresAt: {
[Op.lt]: new Date(),
},
},
limit,
});
await Promise.all(attachments.map((attachment) => attachment.destroy()));
Logger.info("task", `Removed ${attachments.length} attachments`);
}
public get cron() {
return {
interval: TaskInterval.Hour,
};
}
public get options() {
return {
attempts: 1,
priority: TaskPriority.Background,
};
}
}