Initial commit
This commit is contained in:
33
backup 24.2.26 - Kopie (61)/tools/wait_http_ready.py
Normal file
33
backup 24.2.26 - Kopie (61)/tools/wait_http_ready.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import sys
|
||||
import time
|
||||
import urllib.request
|
||||
|
||||
|
||||
def main() -> int:
|
||||
if len(sys.argv) < 3:
|
||||
return 2
|
||||
|
||||
url = (sys.argv[1] or "").strip()
|
||||
try:
|
||||
timeout_sec = int(sys.argv[2])
|
||||
except Exception:
|
||||
timeout_sec = 30
|
||||
|
||||
if not url:
|
||||
return 2
|
||||
|
||||
deadline = time.time() + max(1, timeout_sec)
|
||||
while time.time() < deadline:
|
||||
try:
|
||||
with urllib.request.urlopen(url, timeout=2) as resp:
|
||||
code = getattr(resp, "status", 200)
|
||||
if 200 <= code < 500:
|
||||
return 0
|
||||
except Exception:
|
||||
pass
|
||||
time.sleep(1.0)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user