Retry database readiness in live smoke
This commit is contained in:
@@ -20,13 +20,26 @@ cd /app
|
|||||||
echo "Database URL is read from backend container settings / DATABASE_URL."
|
echo "Database URL is read from backend container settings / DATABASE_URL."
|
||||||
|
|
||||||
python - <<'PY'
|
python - <<'PY'
|
||||||
|
import time
|
||||||
|
|
||||||
from sqlalchemy import text
|
from sqlalchemy import text
|
||||||
|
from sqlalchemy.exc import OperationalError
|
||||||
|
|
||||||
from app.db.session import get_engine
|
from app.db.session import get_engine
|
||||||
|
|
||||||
|
last_error = None
|
||||||
|
for attempt in range(1, 61):
|
||||||
|
try:
|
||||||
with get_engine().connect() as connection:
|
with get_engine().connect() as connection:
|
||||||
connection.execute(text("SELECT 1"))
|
connection.execute(text("SELECT 1"))
|
||||||
print("Database connection: ok")
|
print(f"Database connection: ok after attempt {attempt}")
|
||||||
|
break
|
||||||
|
except OperationalError as exc:
|
||||||
|
last_error = exc
|
||||||
|
print(f"Database not ready yet ({attempt}/60): {exc}")
|
||||||
|
time.sleep(2)
|
||||||
|
else:
|
||||||
|
raise SystemExit(f"Database did not become ready: {last_error}")
|
||||||
PY
|
PY
|
||||||
|
|
||||||
python -m alembic upgrade head
|
python -m alembic upgrade head
|
||||||
@@ -113,13 +126,26 @@ echo "Using Python: $PYTHON_BIN"
|
|||||||
echo "Database URL is read from backend settings / DATABASE_URL."
|
echo "Database URL is read from backend settings / DATABASE_URL."
|
||||||
|
|
||||||
"$PYTHON_BIN" - <<'PY'
|
"$PYTHON_BIN" - <<'PY'
|
||||||
|
import time
|
||||||
|
|
||||||
from sqlalchemy import text
|
from sqlalchemy import text
|
||||||
|
from sqlalchemy.exc import OperationalError
|
||||||
|
|
||||||
from app.db.session import get_engine
|
from app.db.session import get_engine
|
||||||
|
|
||||||
|
last_error = None
|
||||||
|
for attempt in range(1, 61):
|
||||||
|
try:
|
||||||
with get_engine().connect() as connection:
|
with get_engine().connect() as connection:
|
||||||
connection.execute(text("SELECT 1"))
|
connection.execute(text("SELECT 1"))
|
||||||
print("Database connection: ok")
|
print(f"Database connection: ok after attempt {attempt}")
|
||||||
|
break
|
||||||
|
except OperationalError as exc:
|
||||||
|
last_error = exc
|
||||||
|
print(f"Database not ready yet ({attempt}/60): {exc}")
|
||||||
|
time.sleep(2)
|
||||||
|
else:
|
||||||
|
raise SystemExit(f"Database did not become ready: {last_error}")
|
||||||
PY
|
PY
|
||||||
|
|
||||||
"$PYTHON_BIN" -m alembic upgrade head
|
"$PYTHON_BIN" -m alembic upgrade head
|
||||||
|
|||||||
Reference in New Issue
Block a user