Перенести и адаптировать базу лабораторной 5 для отдельного стенда 6

This commit is contained in:
2026-11-27 16:36:53 +03:00
parent 470d9d6f1e
commit 5c3c4a9d0d
49 changed files with 2366 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
"""Явная готовность API, stores и процессов; smoke проверяет обработку задания."""
import argparse
import json
import subprocess
import time
import urllib.error
import urllib.request
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--project', default='lyakhonov-lab6')
parser.add_argument('--base-url', default='http://127.0.0.1:8086')
args = parser.parse_args()
deadline = time.monotonic()+120
observed = set()
while time.monotonic() < deadline:
ids = subprocess.check_output(['docker','compose','-p',args.project,'ps','-q'], text=True).split()
if not ids:
time.sleep(1)
continue
rows = json.loads(subprocess.check_output(['docker','inspect',*ids], text=True))
services = {}
for row in rows:
name = row['Config']['Labels']['com.docker.compose.service']
services.setdefault(name, []).append(row['State'])
running = all(services.get(name) and all(s['Running'] for s in services[name])
for name in ('api','db','s3','broker','dispatcher','worker','staging-cleaner','lb'))
healthy = all(services.get(name) and all(s.get('Health',{}).get('Status') == 'healthy' for s in services[name])
for name in ('db','broker','api'))
try:
with urllib.request.urlopen(args.base_url+'/health/ready', timeout=2) as response:
observed.add(response.headers.get('X-Instance-Id'))
except (urllib.error.URLError, TimeoutError, OSError):
pass
if running and healthy and len(services.get('api', [])) >= 2 and len(observed - {None}) >= 2:
print('PASS: two ready API instances, healthy DB/broker, required background containers running')
return
time.sleep(.5)
raise SystemExit('Readiness deadline exceeded')
if __name__ == '__main__':
main()