From dbc5878fe2ec0a8c39c628287c37b279ea0a10d2 Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 4 Feb 2026 22:32:27 -0500 Subject: [PATCH] Another fix for refresh. --- modules/web_app.py | 6 +++++- templates/bible_comparison.html | 15 ++++++++++++--- templates/project.html | 27 ++++++++++++++++++--------- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/modules/web_app.py b/modules/web_app.py index 2e91bfe..46d5a18 100644 --- a/modules/web_app.py +++ b/modules/web_app.py @@ -1196,7 +1196,11 @@ def rewrite_chapter(run_id): @app.route('/task_status/') @login_required def get_task_status(task_id): - task_result = huey.result(task_id, peek=True) + try: + task_result = huey.result(task_id, preserve=True) + except Exception as e: + # If Huey errors out, report it as a failed task so the UI can react + return {"status": "completed", "success": False, "error": str(e)} if task_result is None: return {"status": "running"} diff --git a/templates/bible_comparison.html b/templates/bible_comparison.html index 963db41..7ed376e 100644 --- a/templates/bible_comparison.html +++ b/templates/bible_comparison.html @@ -152,9 +152,18 @@ function submitRefine(event) { modal.show(); refinePollInterval = setInterval(() => { - fetch(`/task_status/${data.task_id}`).then(r => r.json()).then(status => { - if (status.status === 'completed') window.location.reload(); - }); + fetch(`/task_status/${data.task_id}`) + .then(r => r.json()) + .then(status => { + if (status.status === 'completed') { + clearInterval(refinePollInterval); + if (status.success === false) { + alert("Refinement failed: " + (status.error || "Check logs")); + } + window.location.reload(); + } + }) + .catch(e => console.error(e)); }, 2000); } }) diff --git a/templates/project.html b/templates/project.html index e082d43..446470b 100644 --- a/templates/project.html +++ b/templates/project.html @@ -646,17 +646,26 @@ showRefiningModal(); const pollInterval = setInterval(() => { - fetch(`/task_status/${data.task_id}`).then(r => r.json()).then(status => { - if (status.status === 'completed') { - clearInterval(pollInterval); - if (status.success) { - window.location.href = "/project/{{ project.id }}/bible_comparison"; - } else { - alert("Refinement failed. Please check the logs."); - window.location.reload(); + fetch(`/task_status/${data.task_id}`) + .then(r => { + if (!r.ok) throw new Error("Server error checking status"); + return r.json(); + }) + .then(status => { + if (status.status === 'completed') { + clearInterval(pollInterval); + if (status.success) { + window.location.href = "/project/{{ project.id }}/bible_comparison"; + } else { + alert("Refinement failed: " + (status.error || "Check logs for details.")); + window.location.reload(); + } } + }) + .catch(err => { + console.error("Polling error:", err); } - }); + ); }, 2000); } })