mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-09-12 19:50:57 +05:00
Keep OpenCode recovery nonblocking
This commit is contained in:
parent
00e867d949
commit
a33b333b6a
@ -219,9 +219,17 @@
|
||||
redirect: "manual",
|
||||
};
|
||||
let checking = false;
|
||||
let waking = false;
|
||||
let wasUnavailable = false;
|
||||
let healthyChecks = 0;
|
||||
let knownVersion = "{{ opencode_version|escapejs }}";
|
||||
const wake = () => {
|
||||
if (waking) return;
|
||||
waking = true;
|
||||
fetch(healthUrl, fetchOptions)
|
||||
.catch(() => {})
|
||||
.finally(() => { waking = false; });
|
||||
};
|
||||
const check = async () => {
|
||||
if (checking || (document.hidden && wasUnavailable)) return;
|
||||
checking = true;
|
||||
@ -231,9 +239,7 @@
|
||||
wasUnavailable = true;
|
||||
healthyChecks = 0;
|
||||
if (response.status === 503) {
|
||||
try {
|
||||
await fetch(healthUrl, fetchOptions);
|
||||
} catch {}
|
||||
wake();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -557,10 +557,12 @@ def agent_health_view(request: HttpRequest):
|
||||
|
||||
version = _opencode_version(_settings(config))
|
||||
healthy = bool(version)
|
||||
return JsonResponse(
|
||||
response = JsonResponse(
|
||||
{"healthy": healthy, "version": version},
|
||||
status=200 if healthy else 503,
|
||||
)
|
||||
response.headers["Cache-Control"] = "no-store"
|
||||
return response
|
||||
|
||||
|
||||
def _proxy_url(settings: dict, path: str | None) -> str:
|
||||
|
||||
@ -192,6 +192,8 @@ def test_opencode_agent_superuser_gets_admin_wrapper(admin_client, live_opencode
|
||||
assert b"/admin/agent/opencode/global/health" in response.content
|
||||
assert b"/admin/agent/opencode/_archivebox/health" in response.content
|
||||
assert b'redirect: "manual"' in response.content
|
||||
assert b"let waking = false" in response.content
|
||||
assert b"wake();" in response.content
|
||||
assert b"frame.contentWindow.location.reload()" in response.content
|
||||
assert response.headers["X-Frame-Options"] == "DENY"
|
||||
assert response.headers["Content-Security-Policy"] == "frame-ancestors 'none'"
|
||||
@ -217,6 +219,7 @@ def test_opencode_health_monitor_does_not_start_server(admin_client, live_openco
|
||||
|
||||
assert response.status_code == 503
|
||||
assert response.json() == {"healthy": False, "version": ""}
|
||||
assert response.headers["Cache-Control"] == "no-store"
|
||||
assert views._PROCESS is None
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user