Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions app/api/webhooks/sanity-content/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NextResponse } from 'next/server';
import { NextResponse, after } from 'next/server';
import { isValidSignature, SIGNATURE_HEADER_NAME } from '@sanity/webhook';
import { processVideoProduction } from '@/lib/services/video-pipeline';

Expand Down Expand Up @@ -82,10 +82,16 @@ export async function POST(request: Request) {
);
}

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

return NextResponse.json({ triggered: true }, { status: 200 });
Expand Down
Loading