Erste Produktivversion
This commit is contained in:
31
backend/app/wait_for_db.py
Normal file
31
backend/app/wait_for_db.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""Wartet, bis MariaDB Verbindungen annimmt. Wird vom entrypoint.sh
|
||||
aufgerufen, bevor Alembic laeuft."""
|
||||
import sys
|
||||
import time
|
||||
|
||||
from sqlalchemy import text
|
||||
|
||||
from app.db import engine
|
||||
|
||||
DEADLINE_SECONDS = 90
|
||||
|
||||
|
||||
def main() -> int:
|
||||
start = time.monotonic()
|
||||
while True:
|
||||
try:
|
||||
with engine.connect() as conn:
|
||||
conn.execute(text("SELECT 1"))
|
||||
print("[wait_for_db] Datenbank erreichbar.")
|
||||
return 0
|
||||
except Exception as exc:
|
||||
if time.monotonic() - start > DEADLINE_SECONDS:
|
||||
print(f"[wait_for_db] Aufgegeben nach {DEADLINE_SECONDS}s: {exc}",
|
||||
file=sys.stderr)
|
||||
return 1
|
||||
print(f"[wait_for_db] noch nicht bereit: {type(exc).__name__}")
|
||||
time.sleep(2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user