Мессенджер с Postgres, Redis, Valkey

This commit is contained in:
Queenfish
2026-10-08 13:21:48 +03:00
parent 65003b6119
commit 6bfbcf74fc
41 changed files with 2624 additions and 24 deletions
+2
View File
@@ -0,0 +1,2 @@
@echo off
python "%~dp0restart.py" %*
+52
View File
@@ -0,0 +1,52 @@
#!/usr/bin/env python3
"""Restart API and all used stores, preserving volumes.
Called by tests/resilience.py via --action-script.
Must NOT remove volumes or re-seed the database.
"""
import subprocess
import sys
import time
import urllib.request
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
BASE_URL = "http://localhost:8080"
def run(cmd):
print(f"[restart] $ {' '.join(cmd)}", flush=True)
result = subprocess.run(cmd, cwd=ROOT)
if result.returncode != 0:
print(
f"[restart] command failed with code {result.returncode}",
file=sys.stderr,
)
sys.exit(result.returncode)
def main():
run(["docker", "compose", "--env-file", ".env", "down"])
run(["docker", "compose", "--env-file", ".env", "up", "-d", "--build"])
print("[restart] waiting for /health/ready", flush=True)
deadline = time.monotonic() + 90
while time.monotonic() < deadline:
try:
with urllib.request.urlopen(
f"{BASE_URL}/health/ready", timeout=2
) as r:
if r.status == 200:
print("[restart] api is ready", flush=True)
return 0
except Exception:
time.sleep(1)
print(
"[restart] api did not become ready in 90 seconds",
file=sys.stderr,
)
return 1
if __name__ == "__main__":
sys.exit(main())
+22
View File
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")/.."
echo "[restart.sh] docker compose down (volumes preserved)"
docker compose --env-file .env down
echo "[restart.sh] docker compose up -d --build"
docker compose --env-file .env up -d --build
echo "[restart.sh] waiting for /health/ready"
for i in $(seq 1 90); do
if curl -fsS http://localhost:8080/health/ready >/dev/null 2>&1; then
echo "[restart.sh] api is ready"
exit 0
fi
sleep 1
done
echo "[restart.sh] api did not become ready in 90 seconds" >&2
exit 1