Files
outline/server/queues/tasks/UpdateTeamAttachmentsSizeTask.ts
Tom Moor bc992fb22a refactor: Add jobId hook to BaseTask for deduplicating queued jobs (#13890)
* refactor: Add jobId hook to BaseTask for deduplicating queued jobs

* fix: Drop jobId from APIImportTask, it re-schedules itself while active
2026-09-25 23:44:16 +00:00

40 lines
894 B
TypeScript

import { Attachment, Team } from "@server/models";
import { BaseTask, TaskPriority } from "./base/BaseTask";
import { sequelizeReadOnly } from "@server/storage/database";
type Props = {
/** The teamId to operate on */
teamId: string;
};
/**
* A task that updates the team stats.
*/
export default class UpdateTeamAttachmentsSizeTask extends BaseTask<Props> {
protected jobId({ teamId }: Props) {
return `update-team-attachments-size:${teamId}`;
}
public async perform({ teamId }: Props) {
const sizeInBytes = await Attachment.getTotalSizeForTeam(
sequelizeReadOnly,
teamId
);
if (!sizeInBytes) {
return;
}
await Team.update(
{ approximateTotalAttachmentsSize: sizeInBytes },
{ where: { id: teamId } }
);
}
public get options() {
return {
attempts: 1,
priority: TaskPriority.Background,
};
}
}