feat: implement lab3 API load balancing and failover

This commit is contained in:
sashadugina06
2026-11-06 01:43:33 +03:00
parent 0ab3a341aa
commit 7088791d5c
116 changed files with 7971 additions and 38 deletions
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env python3
import os
import time
import urllib.request
base = os.getenv('BASE_URL', 'http://localhost:8080')
seen = set()
for _ in range(180):
try:
with urllib.request.urlopen(base+'/health/ready', timeout=2) as r:
seen.add(r.headers['X-Instance-Id'])
if len(seen)>=2:
print('Ready: two API instances through LB:', ', '.join(sorted(seen)))
break
except Exception:
pass
time.sleep(.5)
else:
raise SystemExit('Two ready instances not observed in readiness deadline')