lab6: добавить наблюдаемость и закрыть критерии оценки 5

This commit is contained in:
Wladislava1
2026-11-16 22:04:25 +03:00
parent 470d9d6f1e
commit 802e4b58c2
61 changed files with 7420 additions and 23 deletions
+30
View File
@@ -0,0 +1,30 @@
#!/usr/bin/env python3
"""Ждать GET /health/ready через балансировщик. Без токенов и тел ошибок в выводе."""
import os
import sys
import time
import urllib.error
import urllib.request
URL = os.environ.get("BASE_URL", "http://127.0.0.1:8080").rstrip("/") + "/health/ready"
def main():
deadline = time.monotonic() + 90
last = "not-started"
while time.monotonic() < deadline:
try:
response = urllib.request.urlopen(URL, timeout=2)
if response.status == 200 and response.headers.get("X-Instance-Id"):
print("ready")
return 0
last = str(response.status)
except (urllib.error.URLError, TimeoutError, OSError) as exc:
last = type(exc).__name__
time.sleep(1)
print("not ready: " + last, file=sys.stderr)
return 1
if __name__ == "__main__":
raise SystemExit(main())