Fix milestone sharing previews and publisher recovery
This commit is contained in:
@@ -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 } },
|
||||
|
||||
Reference in New Issue
Block a user