Лабораторная 3: реализован стенд с балансировщиком и идемпотентностью

This commit is contained in:
2026-11-22 16:11:18 +03:00
parent 0ab3a341aa
commit 752995515f
31 changed files with 1576 additions and 23 deletions
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env python3
"""Stop exactly ONE API replica selected by TARGET_INSTANCE_ID — called by resilience.py failover test."""
import subprocess
import sys
import os
def main():
target = os.environ.get("TARGET_INSTANCE_ID")
if not target:
print("TARGET_INSTANCE_ID not set", file=sys.stderr)
return 2
# Change to repo root
repo_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
os.chdir(repo_root)
# Stop the specific API service by its compose service name
result = subprocess.run(["docker", "compose", "stop", "--timeout", "5", target], capture_output=True)
if result.returncode != 0:
print(f"docker compose stop {target} failed: {result.stderr.decode()}", file=sys.stderr)
return 1
return 0
if __name__ == "__main__":
sys.exit(main())