This commit is contained in:
2026-11-06 18:09:01 +03:00
parent 0ab3a341aa
commit 8f89c7c43b
68 changed files with 4432 additions and 29 deletions
+26
View File
@@ -0,0 +1,26 @@
"""Проверка живости для Docker HEALTHCHECK: python -m messenger.healthcheck."""
from __future__ import annotations
import os
import urllib.error
import urllib.request
DEFAULT_PORT = "8080"
TIMEOUT_SECONDS = 2
def liveness_url() -> str:
port = os.environ.get("APP_PORT", DEFAULT_PORT).strip() or DEFAULT_PORT
return "http://127.0.0.1:%s/health/live" % port
def main() -> int:
try:
with urllib.request.urlopen(liveness_url(), timeout=TIMEOUT_SECONDS) as response:
return 0 if response.status == 200 else 1
except (urllib.error.URLError, OSError, ValueError):
return 1
if __name__ == "__main__":
raise SystemExit(main())