Merge pull request #895 from mendableai/nsc/redlock-email

Redlock for sending email notifications
This commit is contained in:
Nicolas 2024-11-13 12:45:55 -05:00 committed by GitHub
commit ea1302960f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,6 +6,7 @@ import { logger } from "../../../src/lib/logger";
import { sendSlackWebhook } from "../alerts/slack";
import { getNotificationString } from "./notification_string";
import { AuthCreditUsageChunk } from "../../controllers/v1/types";
import { redlock } from "../redlock";
const emailTemplates: Record<
NotificationType,
@ -88,6 +89,7 @@ export async function sendNotificationInternal(
if (team_id === "preview") {
return { success: true };
}
return await redlock.using([`notification-lock:${team_id}:${notificationType}`], 5000, async () => {
if (!bypassRecentChecks) {
const fifteenDaysAgo = new Date();
@ -171,5 +173,6 @@ export async function sendNotificationInternal(
return { success: false };
}
return { success: true };
return { success: true };
});
}