Files
outline/server/queues/tasks/CollectionAddUserNotificationsTask.ts
T
Tom Moor 42959d66db chore: Add cron task partitioning (#10736)
* wip

* Implementation complete

* tidying

* test

* Address feedback

* Remove duplicative retry logic from UpdateDocumentsPopularityScoreTask.
Now that we're split across many runs this is not neccessary

* Refactor to subclass, config to instance

* Refactor BaseTask to named export

* fix: Missing partition

* tsc

* Feedback
2025-11-27 16:57:52 +01:00

33 lines
938 B
TypeScript

import { NotificationEventType } from "@shared/types";
import { Notification, User } from "@server/models";
import { CollectionUserEvent } from "@server/types";
import { BaseTask, TaskPriority } from "./base/BaseTask";
export default class CollectionAddUserNotificationsTask extends BaseTask<CollectionUserEvent> {
public async perform(event: CollectionUserEvent) {
const recipient = await User.findByPk(event.userId);
if (!recipient) {
return;
}
if (
!recipient.isSuspended &&
recipient.subscribedToEventType(NotificationEventType.AddUserToCollection)
) {
await Notification.create({
event: NotificationEventType.AddUserToCollection,
userId: event.userId,
actorId: event.actorId,
teamId: event.teamId,
collectionId: event.collectionId,
});
}
}
public get options() {
return {
priority: TaskPriority.Background,
};
}
}