Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

finalize cron

Steven Teye002d727f896
diff --git a/apps/web/app/api/cron/program-application-reminder/route.ts b/apps/web/app/api/cron/program-application-reminder/route.ts
index e02b95d7c4..d116c486e9 100644
--- a/apps/web/app/api/cron/program-application-reminder/route.ts
+++ b/apps/web/app/api/cron/program-application-reminder/route.ts
@@ -1,8 +1,10 @@
import { handleAndReturnErrorResponse } from "@/lib/api/errors";
+import { qstash } from "@/lib/cron";
import { verifyQstashSignature } from "@/lib/cron/verify-qstash";
import { sendEmail } from "@dub/email";
import ProgramApplicationReminder from "@dub/email/templates/program-application-reminder";
import { prisma } from "@dub/prisma";
+import { APP_DOMAIN_WITH_NGROK } from "@dub/utils/src/constants";
// POST - /api/cron/program-application-reminder
// Sends an email if a program application hasn't received an associated partner
@@ -13,10 +15,14 @@ export async function POST(req: Request) {
const { applicationId } = JSON.parse(rawBody);
- const application = await prisma.programApplication.findUnique({
+ const application = await prisma.programApplication.findFirst({
where: {
id: applicationId,
partner: null,
+ // Only send reminders for applications that were created less than 3 days ago
+ createdAt: {
+ gt: new Date(Date.now() - 3 * 24 * 60 * 60 * 1000),
+ },
},
include: {
program: {
@@ -33,30 +39,25 @@ export async function POST(req: Request) {
`Application ${applicationId} without partner not found. Skipping...`,
);
- try {
- await sendEmail({
- subject: `Complete your application to ${application.program.name}`,
+ await sendEmail({
+ subject: `Complete your application to ${application.program.name}`,
+ email: application.email,
+ react: ProgramApplicationReminder({
email: application.email,
- react: ProgramApplicationReminder({
- email: application.email,
- program: {
- name: application.program.name,
- },
- }),
- });
+ program: {
+ name: application.program.name,
+ },
+ }),
+ });
- console.log(
- `Sent application reminder email to ${application.email} for application ${applicationId}`,
- );
- } catch (e) {
- console.error(
- `Failed to send application reminder email to ${application.email} for application ${applicationId}`,
- e,
- );
- return new Response(
- `Failed to send application reminder email to ${application.email} for application ${applicationId}`,
- );
- }
+ await qstash.publishJSON({
+ url: `${APP_DOMAIN_WITH_NGROK}/api/cron/program-application-reminder`,
+ // repeat every 24 hours, but it'll be cancelled if the application is more than 3 days old or is associated with a partner
+ delay: 24 * 60 * 60 * 1000,
+ body: {
+ applicationId: application.id,
+ },
+ });
return new Response(
`Email sent to ${application.email} for application ${applicationId}.`,
diff --git a/apps/web/lib/actions/partners/create-program-application.ts b/apps/web/lib/actions/partners/create-program-application.ts
index 7819321716..5dfa61f600 100644
--- a/apps/web/lib/actions/partners/create-program-application.ts
+++ b/apps/web/lib/actions/partners/create-program-application.ts
@@ -82,7 +82,6 @@ export const createProgramApplicationAction = actionClient
body: {
applicationId: application.programApplicationId,
},
- contentBasedDeduplication: true,
});
return application;