Skip to content

Commit 9664e1b

Browse files
author
Miriad
committed
fix: use after() instead of fire-and-forget in video webhook
On Vercel serverless, functions terminate after the response is sent. The fire-and-forget pattern caused the pipeline to silently die after setting audio_gen status. after() keeps the function alive.
1 parent 2597e92 commit 9664e1b

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

app/api/webhooks/sanity-content/route.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NextResponse } from 'next/server';
1+
import { NextResponse, after } from 'next/server';
22
import { isValidSignature, SIGNATURE_HEADER_NAME } from '@sanity/webhook';
33
import { processVideoProduction } from '@/lib/services/video-pipeline';
44

@@ -82,10 +82,16 @@ export async function POST(request: Request) {
8282
);
8383
}
8484

85-
// Fire and forget — trigger pipeline in background, return 200 immediately
85+
// Use after() to run the pipeline after the response is sent.
86+
// On Vercel, serverless functions terminate after the response — fire-and-forget
87+
// (promise.catch() without await) silently dies. after() keeps the function alive.
8688
console.log(`[WEBHOOK] Triggering video production for document: ${body._id}`);
87-
processVideoProduction(body._id).catch((error) => {
88-
console.log(`[WEBHOOK] Background processing error for ${body._id}:`, error);
89+
after(async () => {
90+
try {
91+
await processVideoProduction(body._id);
92+
} catch (error) {
93+
console.error(`[WEBHOOK] Background processing error for ${body._id}:`, error);
94+
}
8995
});
9096

9197
return NextResponse.json({ triggered: true }, { status: 200 });

0 commit comments

Comments
 (0)