Improve reliability of team deletion

This commit is contained in:
Tom Moor
2023-11-13 22:06:24 -05:00
parent 530b8a1989
commit 8c85029d55
3 changed files with 31 additions and 4 deletions

View File

@@ -0,0 +1,25 @@
import teamPermanentDeleter from "@server/commands/teamPermanentDeleter";
import { Team } from "@server/models";
import BaseTask, { TaskPriority } from "./BaseTask";
type Props = {
/** The team ID to permanantly destroy */
teamId: string;
};
export default class CleanupDeletedTeamTask extends BaseTask<Props> {
public async perform({ teamId }: Props) {
const team = await Team.findByPk(teamId, {
paranoid: false,
rejectOnEmpty: true,
});
await teamPermanentDeleter(team);
}
public get options() {
return {
attempts: 1,
priority: TaskPriority.Background,
};
}
}

View File

@@ -1,9 +1,9 @@
import { subDays } from "date-fns";
import { Op } from "sequelize";
import teamPermanentDeleter from "@server/commands/teamPermanentDeleter";
import Logger from "@server/logging/Logger";
import { Team } from "@server/models";
import BaseTask, { TaskPriority, TaskSchedule } from "./BaseTask";
import CleanupDeletedTeamTask from "./CleanupDeletedTeamTask";
type Props = {
limit: number;
@@ -18,6 +18,7 @@ export default class CleanupDeletedTeamsTask extends BaseTask<Props> {
`Permanently destroying upto ${limit} teams older than 30 days…`
);
const teams = await Team.findAll({
attributes: ["id"],
where: {
deletedAt: {
[Op.lt]: subDays(new Date(), 30),
@@ -28,9 +29,10 @@ export default class CleanupDeletedTeamsTask extends BaseTask<Props> {
});
for (const team of teams) {
await teamPermanentDeleter(team);
await CleanupDeletedTeamTask.schedule({
teamId: team.id,
});
}
Logger.info("task", `Destroyed ${teams.length} teams`);
}
public get options() {