feat(wds): live status banner, auto-poll, and instant error emails
- Auto-poll every 15s when sync is running, 60s when idle - Live status banner: running (with city/step), error list, weekend window waiting, connection error - Highlight active city card and currently-running step with pulse animation - Send immediate error email per failed step (not just at session end) - Expose syncStatus/currentActivity/inWeekendWindow in API response - Stop silently swallowing fetch/action errors — show them in the UI Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { PrismaClient, Prisma } from "@prisma/client";
|
||||
import {
|
||||
isWeekendWindow,
|
||||
getWeekendSyncActivity,
|
||||
} from "@/modules/parcel-sync/services/weekend-deep-sync";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
const g = globalThis as { __parcelSyncRunning?: boolean };
|
||||
|
||||
const KV_NAMESPACE = "parcel-sync-weekend";
|
||||
const KV_KEY = "queue-state";
|
||||
|
||||
@@ -116,8 +122,25 @@ export async function GET() {
|
||||
dbStats: statsMap.get(c.siruta) ?? { terenuri: 0, cladiri: 0, total: 0, enriched: 0 },
|
||||
}));
|
||||
|
||||
// Determine live sync status
|
||||
const running = !!g.__parcelSyncRunning;
|
||||
const activity = getWeekendSyncActivity();
|
||||
const inWindow = isWeekendWindow();
|
||||
const hasErrors = state.cities.some((c) =>
|
||||
(Object.values(c.steps) as StepStatus[]).some((s) => s === "error"),
|
||||
);
|
||||
|
||||
type SyncStatus = "running" | "error" | "waiting" | "idle";
|
||||
let syncStatus: SyncStatus = "idle";
|
||||
if (running) syncStatus = "running";
|
||||
else if (hasErrors) syncStatus = "error";
|
||||
else if (inWindow) syncStatus = "waiting";
|
||||
|
||||
return NextResponse.json({
|
||||
state: { ...state, cities: citiesWithStats },
|
||||
syncStatus,
|
||||
currentActivity: activity,
|
||||
inWeekendWindow: inWindow,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user