Files
outline/server/queues/tasks/CleanupExpiredAttachmentsTask.ts
Tom Moor 60101c507a Move bulk of webhook logic to plugin (#4866)
* Move bulk of webhook logic to plugin

* Re-enable cleanup task

* cron tasks
2023-02-12 16:28:11 -08:00

34 lines
877 B
TypeScript

import { Op } from "sequelize";
import Logger from "@server/logging/Logger";
import { Attachment } from "@server/models";
import BaseTask, { TaskPriority, TaskSchedule } from "./BaseTask";
type Props = {
limit: number;
};
export default class CleanupExpiredAttachmentsTask extends BaseTask<Props> {
static cron = TaskSchedule.Daily;
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 options() {
return {
attempts: 1,
priority: TaskPriority.Background,
};
}
}