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) <noreply@anthropic.com>
This commit is contained in:
@@ -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"] });
|
||||
}}
|
||||
>
|
||||
<Play className="h-4 w-4 mr-1" />
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -277,8 +277,10 @@ type SessionLog = {
|
||||
|
||||
export async function runWeekendDeepSync(options?: {
|
||||
force?: boolean;
|
||||
onlySteps?: StepName[];
|
||||
}): Promise<void> {
|
||||
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}`);
|
||||
|
||||
Reference in New Issue
Block a user