Files
outline/server/queues/tasks/CleanupExpiredAttachmentsTask.ts
Tom Moor bf45e97641 chore: Enforce type import consistency (#10968)
* Update types

* fix circular dep

* type imports

* lint type imports and --fix
2025-12-19 23:07:02 -05:00

36 lines
964 B
TypeScript

import { Op } from "sequelize";
import Logger from "@server/logging/Logger";
import { Attachment } from "@server/models";
import { TaskPriority } from "./base/BaseTask";
import type { Props } from "./base/CronTask";
import { CronTask, 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,
};
}
}