Notifications refactor (#5151

* Ongoing

* refactor

* test

* Add cleanup task

* refactor
This commit is contained in:
Tom Moor
2023-04-08 09:22:49 -04:00
committed by GitHub
parent c97110e72b
commit 9c9ceef8ee
28 changed files with 1122 additions and 901 deletions

View File

@@ -0,0 +1,52 @@
import { subMonths } from "date-fns";
import { Op } from "sequelize";
import Logger from "@server/logging/Logger";
import { Notification } from "@server/models";
import BaseTask, { TaskPriority, TaskSchedule } from "./BaseTask";
type Props = Record<string, never>;
export default class CleanupOldNotificationsTask extends BaseTask<Props> {
static cron = TaskSchedule.Daily;
public async perform() {
Logger.info("task", `Permanently destroying old notifications…`);
let count;
count = await Notification.destroy({
where: {
createdAt: {
[Op.lt]: subMonths(new Date(), 12),
},
},
});
Logger.info(
"task",
`Destroyed ${count} notifications older than 12 months…`
);
count = await Notification.destroy({
where: {
viewedAt: {
[Op.ne]: null,
},
createdAt: {
[Op.lt]: subMonths(new Date(), 6),
},
},
});
Logger.info(
"task",
`Destroyed ${count} viewed notifications older than 6 months…`
);
}
public get options() {
return {
attempts: 1,
priority: TaskPriority.Background,
};
}
}