🚧 Temporarily disable message queue (#1449)

This commit is contained in:
Luke Vella 2024-11-30 20:07:50 +00:00 committed by GitHub
parent 3f405003fd
commit 9b606bdbdc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 31 deletions

View file

@ -1,28 +1,33 @@
import * as Sentry from "@sentry/nextjs";
import { verifySignatureAppRouter } from "@upstash/qstash/dist/nextjs";
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { getEmailClient } from "@/utils/emails";
import { verifySignature } from "./verify-signature";
export const POST = async (req: NextRequest) => {
/**
* We need to call verifySignatureAppRouter inside the route handler
* to avoid the build breaking when env vars are not set.
*/
return verifySignatureAppRouter(async (req: NextRequest) => {
const body = await req.json();
export const POST = verifySignature(async (req: NextRequest) => {
const body = await req.json();
// TODO: Add validation for templateName and options
// TODO: Add validation for templateName and options
const emailClient = getEmailClient(body.locale);
const emailClient = getEmailClient(body.locale);
try {
await emailClient.sendTemplate(body.templateName, body.options);
try {
await emailClient.sendTemplate(body.templateName, body.options);
return NextResponse.json({ success: true });
} catch (error) {
Sentry.captureException(error);
return NextResponse.json({ success: true });
} catch (error) {
Sentry.captureException(error);
return NextResponse.json(
{ success: false, error: "Failed to send email" },
{ status: 500 },
);
}
});
return NextResponse.json(
{ success: false, error: "Failed to send email" },
{ status: 500 },
);
}
})(req);
};

View file

@ -1,12 +0,0 @@
import { verifySignatureAppRouter } from "@upstash/qstash/dist/nextjs";
import type { NextRequest } from "next/server";
export async function verifySignature(
handler: (req: NextRequest) => Promise<Response>,
) {
/**
* We need to call verifySignatureAppRouter inside the route handler
* to avoid the build breaking when env vars are not set.
*/
return (req: NextRequest) => verifySignatureAppRouter(handler)(req);
}

View file

@ -72,12 +72,13 @@ export class EmailClient {
templateName: T,
options: SendEmailOptions<T>,
) {
const isQueueEnabled = false; // TODO: Enable this
const createEmailJob = async () => {
const client = createQstashClient();
if (client) {
if (client && isQueueEnabled) {
const queue = client.queue({
queueName: "emails",
queueName: "emails-mq",
});
queue