mirror of
https://github.com/calibrain/shelfmark.git
synced 2026-11-25 21:11:24 +00:00
fix: report a stopped download coordinator in /api/health (#1568)
If the download coordinator thread dies, every task sits at "Queued" and nothing says why. The rest of the app keeps answering, `/api/health` stays green and the container looks fine. #823 and #1166 were both that, and the loop's `except Exception` cannot catch everything that can end a thread. `/api/health` now reports it. The response gets a `coordinator` field, `running` or `stopped`, and when it is stopped the status is `error` and the HTTP code is 503. The Docker healthcheck in the Dockerfile and the one in the readme both use `curl -f`, so the container shows as unhealthy and anything watching health (Uptime Kuma, autoheal) can act on it. It needs no login, same as before, and shows no queue contents. That 503 is the one decision here. Keeping the 200 and only adding a `degraded` entry would not trip a status-code health check, which is the whole point, so I went with 503. Easy to flip if you would rather not. The orchestrator gets a small `coordinator_running()` that asks whether the thread is alive. `start()` already knows how to restart a dead thread, so restarting it automatically would be the true fix, but I would rather the failure be visible first and decide on that separately. Tests: three for the route (ok, 503, no login needed) and three for `coordinator_running` (never started, alive, dead). They fail without the change. One existing test hits `/api/health` through an app that never starts the coordinator, so it now patches that. The readme's health section has a sentence about the 503. Full suite passes, ruff and basedpyright are clean.
This commit is contained in:
1 parent
973cf472a2
commit
ef40a38546
5 files changed
+102
-2
No files matched your search
@@ -307,7 +307,9 @@ class TestMismatchFallsThrough:
|
||||
class TestScopeAndModes:
|
||||
def test_health_and_auth_paths_and_root_ignore_key(self, wired):
|
||||
client = wired.app.test_client()
|
||||
assert client.get("/api/health", headers=_bearer("s3cret")).status_code == 200
|
||||
# The test app never starts the coordinator, which /api/health reports.
|
||||
with patch.object(wired.backend, "coordinator_running", return_value=True):
|
||||
assert client.get("/api/health", headers=_bearer("s3cret")).status_code == 200
|
||||
assert (
|
||||
client.get("/api/auth/check", headers=_bearer("s3cret")).get_json()["authenticated"]
|
||||
is False
|
||||
|
||||
Reference in new issue
Block a user