Skip to content

Commit 51a3abb

Browse files
author
Miriad
committed
fix: detect and flag stale audio_gen documents in check-renders
Documents stuck in audio_gen for >10 minutes (from pipeline timeouts) are now automatically flagged with a helpful message to reset to script_ready to retry.
1 parent 8f73005 commit 51a3abb

1 file changed

Lines changed: 26 additions & 6 deletions

File tree

app/api/cron/check-renders/route.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,32 @@ export async function GET(request: NextRequest) {
6666
}`
6767
);
6868

69-
if (renderingDocs.length === 0) {
70-
console.log('[CHECK-RENDERS] No documents in "rendering" status');
71-
return Response.json({ processed: 0, results: [] });
69+
// Also find docs stuck in "audio_gen" for more than 10 minutes (pipeline timed out)
70+
const stuckDocs = await client.fetch<Array<{ _id: string; title?: string; _updatedAt: string }>>(
71+
`*[_type == "automatedVideo" && status == "audio_gen" && dateTime(_updatedAt) < dateTime(now()) - 60*10]{
72+
_id, title, _updatedAt
73+
}`
74+
);
75+
76+
// Flag stuck audio_gen docs
77+
for (const doc of stuckDocs) {
78+
console.log(`[CHECK-RENDERS] Flagging stuck document "${doc.title || doc._id}" (audio_gen since ${doc._updatedAt})`);
79+
try {
80+
await client.patch(doc._id).set({
81+
status: 'flagged',
82+
flaggedReason: `Pipeline timed out during audio generation. Document stuck in audio_gen since ${doc._updatedAt}. Reset status to script_ready to retry.`,
83+
}).commit();
84+
} catch (err) {
85+
console.error(`[CHECK-RENDERS] Failed to flag stuck doc ${doc._id}:`, err);
86+
}
87+
}
88+
89+
if (renderingDocs.length === 0 && stuckDocs.length === 0) {
90+
console.log('[CHECK-RENDERS] No documents to process');
91+
return Response.json({ processed: 0, stuckFlagged: 0, results: [] });
7292
}
7393

74-
console.log(`[CHECK-RENDERS] Found ${renderingDocs.length} document(s) to check`);
94+
console.log(`[CHECK-RENDERS] Found ${renderingDocs.length} rendering, ${stuckDocs.length} stuck`);
7595

7696
const results: ProcessResult[] = [];
7797

@@ -184,6 +204,6 @@ export async function GET(request: NextRequest) {
184204
}
185205
}
186206

187-
console.log(`[CHECK-RENDERS] Done. Processed ${results.length} document(s).`);
188-
return Response.json({ processed: results.length, results });
207+
console.log(`[CHECK-RENDERS] Done. Processed ${results.length} rendering, ${stuckDocs.length} stuck flagged.`);
208+
return Response.json({ processed: results.length, stuckFlagged: stuckDocs.length, results });
189209
}

0 commit comments

Comments
 (0)