32 lines
854 B
Python
32 lines
854 B
Python
"""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())
|