The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
use queueBatchEmail for charge-succeeded cron as well
Steven Tey38fa54d61909
diff --git a/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/route.ts b/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/route.tsindex fdfaa4c8ee..9b920583b0 100644--- a/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/route.ts+++ b/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/route.ts@@ -6,7 +6,10 @@ import { APP_DOMAIN_WITH_NGROK, log } from "@dub/utils";import { z } from "zod";import { logAndRespond } from "../../utils";import { sendPaypalPayouts } from "./send-paypal-payouts";-import { sendStripePayouts } from "./send-stripe-payouts";+import {+ SEND_PAYOUTS_BATCH_SIZE,+ sendStripePayouts,+} from "./send-stripe-payouts";export const dynamic = "force-dynamic";@@ -86,9 +89,9 @@ export async function POST(req: Request) {}),]);- if (invoice._count.payouts > 100) {+ if (invoice._count.payouts > SEND_PAYOUTS_BATCH_SIZE) {console.log(- "More than 100 payouts found for invoice, scheduling next batch...",+ `More than ${SEND_PAYOUTS_BATCH_SIZE} payouts found for invoice, scheduling next batch...`,);const qstashResponse = await qstash.publishJSON({url: `${APP_DOMAIN_WITH_NGROK}/api/cron/payouts/charge-succeeded`,diff --git a/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/send-stripe-payouts.ts b/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/send-stripe-payouts.tsindex e68679f0f4..e4eb0c58eb 100644--- a/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/send-stripe-payouts.ts+++ b/apps/web/app/(ee)/api/cron/payouts/charge-succeeded/send-stripe-payouts.ts@@ -1,9 +1,11 @@+import { queueBatchEmail } from "@/lib/email/queue-batch-email";import { createStripeTransfer } from "@/lib/partners/create-stripe-transfer";-import { sendBatchEmail } from "@dub/email";import PartnerPayoutProcessed from "@dub/email/templates/partner-payout-processed";import { prisma } from "@dub/prisma";import { Prisma } from "@prisma/client";+export const SEND_PAYOUTS_BATCH_SIZE = 500;+export async function sendStripePayouts({invoiceId,chargeId,@@ -42,7 +44,7 @@ export async function sendStripePayouts({},},include: commonInclude,- take: 100,+ take: SEND_PAYOUTS_BATCH_SIZE,});if (currentInvoicePayouts.length === 0) {@@ -95,21 +97,20 @@ export async function sendStripePayouts({});}- const resendBatch = await sendBatchEmail(+ await queueBatchEmail<typeof PartnerPayoutProcessed>(currentInvoicePayouts.filter((p) => p.partner.email).map((p) => ({variant: "notifications",to: p.partner.email!,subject: "You've been paid!",- react: PartnerPayoutProcessed({+ templateName: "PartnerPayoutProcessed",+ templateProps: {email: p.partner.email!,program: p.program,payout: p,variant: "stripe",- }),+ },})),);-- console.log("Sent Resend batch emails", JSON.stringify(resendBatch, null, 2));}diff --git a/apps/web/lib/email/email-templates-map.ts b/apps/web/lib/email/email-templates-map.tsindex 61931425f9..281243cd80 100644--- a/apps/web/lib/email/email-templates-map.ts+++ b/apps/web/lib/email/email-templates-map.ts@@ -1,5 +1,7 @@import PartnerPayoutConfirmed from "@dub/email/templates/partner-payout-confirmed";+import PartnerPayoutProcessed from "@dub/email/templates/partner-payout-processed";export const EMAIL_TEMPLATES_MAP = {PartnerPayoutConfirmed,+ PartnerPayoutProcessed,} as const;