Fix historical sync progress reload loop

This commit is contained in:
A R R R Associates
2026-08-23 12:45:44 +05:30
parent 4c6546f48d
commit fdce64ebd2
2 changed files with 19 additions and 2 deletions
@@ -20,6 +20,7 @@
{% if latest_run %} {% if latest_run %}
<section id="historicalRunProgress" <section id="historicalRunProgress"
data-status-url="/tools/accounting/historical-learning/run/{{ latest_run.id }}/status" data-status-url="/tools/accounting/historical-learning/run/{{ latest_run.id }}/status"
data-run-status="{{ latest_run.status }}"
class="rounded-2xl border border-blue-200 bg-white p-5 shadow-soft"> class="rounded-2xl border border-blue-200 bg-white p-5 shadow-soft">
<div class="flex flex-wrap items-center justify-between gap-3"> <div class="flex flex-wrap items-center justify-between gap-3">
<div> <div>
@@ -84,6 +85,9 @@ const s=document.getElementById('wsCompany'); if(s){s.addEventListener('change',
const box = document.getElementById("historicalRunProgress"); const box = document.getElementById("historicalRunProgress");
if (!box) return; if (!box) return;
const url = box.dataset.statusUrl; const url = box.dataset.statusUrl;
const initialStatus = String(box.dataset.runStatus || "").toLowerCase();
const terminalAtLoad = ["completed", "failed", "cancelled"].includes(initialStatus);
const label = document.getElementById("runProgressLabel"); const label = document.getElementById("runProgressLabel");
const detail = document.getElementById("runProgressDetail"); const detail = document.getElementById("runProgressDetail");
const meta = document.getElementById("runProgressMeta"); const meta = document.getElementById("runProgressMeta");
@@ -150,7 +154,12 @@ const s=document.getElementById('wsCompany'); if(s){s.addEventListener('change',
if (!completedReloaded) window.setTimeout(poll, 3000); if (!completedReloaded) window.setTimeout(poll, 3000);
} }
// If this page was rendered with an already-terminal latest run,
// do not poll it and do not reload. This prevents an endless
// Completed -> reload -> Completed -> reload loop.
if (!terminalAtLoad) {
poll(); poll();
}
})(); })();
</script> </script>
@@ -135,6 +135,9 @@
const box = document.getElementById("historicalRunProgress"); const box = document.getElementById("historicalRunProgress");
if (!box) return; if (!box) return;
const url = box.dataset.statusUrl; const url = box.dataset.statusUrl;
const initialStatus = String(box.dataset.runStatus || "").toLowerCase();
const terminalAtLoad = ["completed", "failed", "cancelled"].includes(initialStatus);
const label = document.getElementById("runProgressLabel"); const label = document.getElementById("runProgressLabel");
const detail = document.getElementById("runProgressDetail"); const detail = document.getElementById("runProgressDetail");
const meta = document.getElementById("runProgressMeta"); const meta = document.getElementById("runProgressMeta");
@@ -201,7 +204,12 @@
if (!completedReloaded) window.setTimeout(poll, 3000); if (!completedReloaded) window.setTimeout(poll, 3000);
} }
// If this page was rendered with an already-terminal latest run,
// do not poll it and do not reload. This prevents an endless
// Completed -> reload -> Completed -> reload loop.
if (!terminalAtLoad) {
poll(); poll();
}
})(); })();
</script> </script>