Fix historical sync progress reload loop
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
poll();
|
// 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();
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
</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);
|
||||||
}
|
}
|
||||||
|
|
||||||
poll();
|
// 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();
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user