31 lines
940 B
Python
31 lines
940 B
Python
#!/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())
|