From b8061ae31f900369251e315f0dc79e9ba75898f2 Mon Sep 17 00:00:00 2001 From: AI Assistant Date: Mon, 30 Mar 2026 07:36:35 +0300 Subject: [PATCH] feat(wds): limit force sync to terenuri + cladiri only Manual trigger now only processes sync_terenuri and sync_cladiri steps. import_nogeom and enrich are left for the regular weekend window. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/app/(modules)/wds/page.tsx | 4 ++-- src/app/api/eterra/weekend-sync/route.ts | 9 ++++++++- .../parcel-sync/services/weekend-deep-sync.ts | 15 +++++++++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/app/(modules)/wds/page.tsx b/src/app/(modules)/wds/page.tsx index 4571891..4e0a45d 100644 --- a/src/app/(modules)/wds/page.tsx +++ b/src/app/(modules)/wds/page.tsx @@ -259,8 +259,8 @@ export default function WeekendDeepSyncPage() { className="text-indigo-600 border-indigo-300 hover:bg-indigo-50 dark:text-indigo-400 dark:border-indigo-700 dark:hover:bg-indigo-950/30" disabled={actionLoading} onClick={() => { - if (window.confirm("Pornesti sincronizarea manuala? Va procesa toti pasii pending.")) - void doAction({ action: "trigger" }); + if (window.confirm("Pornesti sincronizarea manuala? Va sincroniza terenuri + cladiri.")) + void doAction({ action: "trigger", onlySteps: ["sync_terenuri", "sync_cladiri"] }); }} > diff --git a/src/app/api/eterra/weekend-sync/route.ts b/src/app/api/eterra/weekend-sync/route.ts index 9a99b9d..2dee182 100644 --- a/src/app/api/eterra/weekend-sync/route.ts +++ b/src/app/api/eterra/weekend-sync/route.ts @@ -157,11 +157,18 @@ export async function POST(request: Request) { name?: string; county?: string; priority?: number; + onlySteps?: string[]; }; // Trigger is handled separately — starts sync immediately if (body.action === "trigger") { - const result = await triggerForceSync(); + const validSteps = ["sync_terenuri", "sync_cladiri", "import_nogeom", "enrich"] as const; + const onlySteps = body.onlySteps?.filter((s): s is (typeof validSteps)[number] => + (validSteps as readonly string[]).includes(s), + ); + const result = await triggerForceSync( + onlySteps && onlySteps.length > 0 ? { onlySteps } : undefined, + ); if (!result.started) { return NextResponse.json( { error: result.reason }, diff --git a/src/modules/parcel-sync/services/weekend-deep-sync.ts b/src/modules/parcel-sync/services/weekend-deep-sync.ts index 06e5f6c..191f8d4 100644 --- a/src/modules/parcel-sync/services/weekend-deep-sync.ts +++ b/src/modules/parcel-sync/services/weekend-deep-sync.ts @@ -277,8 +277,10 @@ type SessionLog = { export async function runWeekendDeepSync(options?: { force?: boolean; + onlySteps?: StepName[]; }): Promise { const force = options?.force ?? false; + const activeSteps = options?.onlySteps ?? STEPS; const username = process.env.ETERRA_USERNAME; const password = process.env.ETERRA_PASSWORD; if (!username || !password) return; @@ -327,7 +329,7 @@ export async function runWeekendDeepSync(options?: { }); // Round-robin: iterate through steps, for each step iterate through cities - for (const stepName of STEPS) { + for (const stepName of activeSteps) { // Find cities that still need this step const needsStep = sorted.filter((c) => c.steps[stepName] === "pending"); if (needsStep.length === 0) continue; @@ -633,7 +635,9 @@ async function sendStatusEmail( * Resets error steps, clears lastSessionDate, and starts immediately. * Uses an extended night window (22:00–05:00) for the stillInWindow check. */ -export async function triggerForceSync(): Promise<{ started: boolean; reason?: string }> { +export async function triggerForceSync(options?: { + onlySteps?: StepName[]; +}): Promise<{ started: boolean; reason?: string }> { if (g.__parcelSyncRunning) { return { started: false, reason: "O sincronizare ruleaza deja" }; } @@ -665,8 +669,11 @@ export async function triggerForceSync(): Promise<{ started: boolean; reason?: s g.__parcelSyncRunning = true; void (async () => { try { - console.log("[weekend-sync] Force sync declansat manual."); - await runWeekendDeepSync({ force: true }); + const stepNames = options?.onlySteps; + console.log( + `[weekend-sync] Force sync declansat manual.${stepNames ? ` Steps: ${stepNames.join(", ")}` : ""}`, + ); + await runWeekendDeepSync({ force: true, onlySteps: stepNames }); } catch (err) { const msg = err instanceof Error ? err.message : String(err); console.error(`[weekend-sync] Force sync eroare: ${msg}`);