Skip to content

Commit 34b272d

Browse files
committed
fix: skipped, cancelled emails cant be retried now
1 parent 1eea2e9 commit 34b272d

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

apps/backend/src/app/api/latest/emails/outbox/crud.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ export const emailOutboxCrudHandlers = createLazyProxy(() => createCrudHandlers(
381381
// Cancel action - mark as skipped
382382
set("isPaused", Prisma.sql`false`);
383383
set("isQueued", Prisma.sql`false`);
384+
setNull("nextSendRetryAt"); // Clear any pending retry so it won't be picked up
384385
set("skippedReason", Prisma.sql`'MANUALLY_CANCELLED'::"EmailOutboxSkippedReason"`);
385386
set("skippedDetails", Prisma.sql`'{}'::jsonb`);
386387
} else {

apps/backend/src/lib/email-queue-step.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ async function prepareSendPlan(deltaSeconds: number): Promise<TenancySendBatch[]
524524
const tenancyIds = await globalPrismaClient.emailOutbox.findMany({
525525
where: {
526526
isPaused: false,
527+
skippedReason: null, // Don't process skipped/cancelled emails
528+
finishedSendingAt: null, // Don't process already-finished emails (defense in depth)
527529
OR: [
528530
// Normal case: queued, not started, and no pending retry
529531
{ startedSendingAt: null, isQueued: true, nextSendRetryAt: null },
@@ -561,6 +563,8 @@ async function claimEmailsForSending(tx: PrismaClientTransaction, tenancyId: str
561563
FROM "EmailOutbox"
562564
WHERE "tenancyId" = ${tenancyId}::uuid
563565
AND "isPaused" = FALSE
566+
AND "skippedReason" IS NULL -- Don't process skipped/cancelled emails
567+
AND "finishedSendingAt" IS NULL -- Don't process already-finished emails (defense in depth)
564568
AND "finishedRenderingAt" IS NOT NULL
565569
AND (
566570
-- Normal case: queued, not started, and no pending retry

0 commit comments

Comments
 (0)