forked from mtusi2026/mtusi2026lab7
solution
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
"""Проверка живости worker/relay по heartbeat-файлу для Docker HEALTHCHECK."""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
DEFAULT_TIMEOUT_SECONDS = 30.0
|
||||
|
||||
|
||||
def main() -> int:
|
||||
path = Path(os.environ.get("HEARTBEAT_FILE", "/tmp/messenger-worker-heartbeat"))
|
||||
timeout = float(os.environ.get("HEARTBEAT_TIMEOUT_SECONDS", DEFAULT_TIMEOUT_SECONDS))
|
||||
try:
|
||||
age = time.time() - path.stat().st_mtime
|
||||
except OSError:
|
||||
return 1
|
||||
return 0 if age <= timeout else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user