From 58b4f69d63e395f5cd583b6faf59c16928e698de Mon Sep 17 00:00:00 2001 From: ajp_anton Date: Sun, 9 Aug 2026 18:26:25 +0000 Subject: [PATCH] Update Python tools --- python-tools/app/web.py | 10 +++++++--- python-tools/static/app.js | 14 +++++++++++--- python-tools/templates/run.html | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/python-tools/app/web.py b/python-tools/app/web.py index 08ebdb4..02ed6a2 100644 --- a/python-tools/app/web.py +++ b/python-tools/app/web.py @@ -139,6 +139,7 @@ def create_app(settings: Settings | None = None) -> Flask: "run.html", run=run, children=store.children(run.id), + output=read_run_output(run), ) @app.post("/runs//cancel") @@ -153,12 +154,15 @@ def create_app(settings: Settings | None = None) -> Flask: run = store.get(run_id) if run is None: abort(404) + return {"output": read_run_output(run)} + + def read_run_output(run) -> str: if not run.log_path: - return {"output": ""} + return "" try: - return {"output": Path(run.log_path).read_text(encoding="utf-8", errors="replace")} + return Path(run.log_path).read_text(encoding="utf-8", errors="replace") except FileNotFoundError: - return {"output": ""} + return "" @app.get("/runs//artifacts") def run_artifacts(run_id: int): diff --git a/python-tools/static/app.js b/python-tools/static/app.js index 407cc66..4a3fff1 100644 --- a/python-tools/static/app.js +++ b/python-tools/static/app.js @@ -1,21 +1,29 @@ const output = document.querySelector("#run-output"); if (output) { + let refreshTimer; const refresh = async () => { const response = await fetch(output.dataset.outputUrl, { cache: "no-store" }); if (response.ok) { - output.textContent = (await response.json()).output; + const nextOutput = (await response.json()).output; + if (nextOutput !== output.textContent) { + output.textContent = nextOutput; + } } const status = document.querySelector("#run-status"); if (status) { const stateResponse = await fetch(status.dataset.stateUrl, { cache: "no-store" }); if (stateResponse.ok) { - status.textContent = (await stateResponse.json()).status; + const state = await stateResponse.json(); + status.textContent = state.status; + if (state.status !== "queued" && state.status !== "running") { + window.clearInterval(refreshTimer); + } } } }; refresh(); - window.setInterval(refresh, 2000); + refreshTimer = window.setInterval(refresh, 2000); } const refreshArtifacts = async (container) => { diff --git a/python-tools/templates/run.html b/python-tools/templates/run.html index d2a8618..1b4c71f 100644 --- a/python-tools/templates/run.html +++ b/python-tools/templates/run.html @@ -29,5 +29,5 @@

    Output

    -
    
    +  
    {{ output }}
    {% endblock %}