Fix milestone sharing previews and publisher recovery

This commit is contained in:
2026-08-14 14:33:29 +02:00
parent e7581e488d
commit d8f7202bf6
10 changed files with 265 additions and 43 deletions

View File

@@ -20,6 +20,12 @@ export async function GET(request: NextRequest) {
if (!isAuthorized(request)) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
const dryRun = request.nextUrl.searchParams.get('dryRun') === 'true';
const now = Date.now();
// A worker can be interrupted after claiming a row. Surface that state as a
// retryable failure instead of leaving the dashboard in "processing" forever.
await db.socialMilestone.updateMany({
where: { brandStatus: 'processing', claimedAt: { lt: new Date(now - 5 * 60 * 1000) } },
data: { brandStatus: 'failed', brandPostError: 'The publisher was interrupted before it confirmed the post. Please retry.' },
});
const approvalNotBefore = new Date(now - approvalDelayHours() * 60 * 60 * 1000);
const milestone = await db.socialMilestone.findFirst({
where: { brandStatus: 'approved', brandApprovedAt: { lte: approvalNotBefore } },