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"
|
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}
|
disabled={actionLoading}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (window.confirm("Pornesti sincronizarea manuala? Va procesa toti pasii pending."))
|
if (window.confirm("Pornesti sincronizarea manuala? Va sincroniza terenuri + cladiri."))
|
||||||
void doAction({ action: "trigger" });
|
void doAction({ action: "trigger", onlySteps: ["sync_terenuri", "sync_cladiri"] });
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Play className="h-4 w-4 mr-1" />
|
<Play className="h-4 w-4 mr-1" />
|
||||||
|
|||||||
@@ -157,11 +157,18 @@ export async function POST(request: Request) {
|
|||||||
name?: string;
|
name?: string;
|
||||||
county?: string;
|
county?: string;
|
||||||
priority?: number;
|
priority?: number;
|
||||||
|
onlySteps?: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
// Trigger is handled separately — starts sync immediately
|
// Trigger is handled separately — starts sync immediately
|
||||||
if (body.action === "trigger") {
|
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) {
|
if (!result.started) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ error: result.reason },
|
{ error: result.reason },
|
||||||
|
|||||||
@@ -277,8 +277,10 @@ type SessionLog = {
|
|||||||
|
|
||||||
export async function runWeekendDeepSync(options?: {
|
export async function runWeekendDeepSync(options?: {
|
||||||
force?: boolean;
|
force?: boolean;
|
||||||
|
onlySteps?: StepName[];
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
const force = options?.force ?? false;
|
const force = options?.force ?? false;
|
||||||
|
const activeSteps = options?.onlySteps ?? STEPS;
|
||||||
const username = process.env.ETERRA_USERNAME;
|
const username = process.env.ETERRA_USERNAME;
|
||||||
const password = process.env.ETERRA_PASSWORD;
|
const password = process.env.ETERRA_PASSWORD;
|
||||||
if (!username || !password) return;
|
if (!username || !password) return;
|
||||||
@@ -327,7 +329,7 @@ export async function runWeekendDeepSync(options?: {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Round-robin: iterate through steps, for each step iterate through cities
|
// 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
|
// Find cities that still need this step
|
||||||
const needsStep = sorted.filter((c) => c.steps[stepName] === "pending");
|
const needsStep = sorted.filter((c) => c.steps[stepName] === "pending");
|
||||||
if (needsStep.length === 0) continue;
|
if (needsStep.length === 0) continue;
|
||||||
@@ -633,7 +635,9 @@ async function sendStatusEmail(
|
|||||||
* Resets error steps, clears lastSessionDate, and starts immediately.
|
* Resets error steps, clears lastSessionDate, and starts immediately.
|
||||||
* Uses an extended night window (22:00–05:00) for the stillInWindow check.
|
* 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) {
|
if (g.__parcelSyncRunning) {
|
||||||
return { started: false, reason: "O sincronizare ruleaza deja" };
|
return { started: false, reason: "O sincronizare ruleaza deja" };
|
||||||
}
|
}
|
||||||
@@ -665,8 +669,11 @@ export async function triggerForceSync(): Promise<{ started: boolean; reason?: s
|
|||||||
g.__parcelSyncRunning = true;
|
g.__parcelSyncRunning = true;
|
||||||
void (async () => {
|
void (async () => {
|
||||||
try {
|
try {
|
||||||
console.log("[weekend-sync] Force sync declansat manual.");
|
const stepNames = options?.onlySteps;
|
||||||
await runWeekendDeepSync({ force: true });
|
console.log(
|
||||||
|
`[weekend-sync] Force sync declansat manual.${stepNames ? ` Steps: ${stepNames.join(", ")}` : ""}`,
|
||||||
|
);
|
||||||
|
await runWeekendDeepSync({ force: true, onlySteps: stepNames });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const msg = err instanceof Error ? err.message : String(err);
|
const msg = err instanceof Error ? err.message : String(err);
|
||||||
console.error(`[weekend-sync] Force sync eroare: ${msg}`);
|
console.error(`[weekend-sync] Force sync eroare: ${msg}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user