fix: Improve database connection retry logic with detailed error messages
All checks were successful
Run Tests / Lint (push) Successful in 35s
Run Tests / Unit Tests (push) Successful in 47s

This commit is contained in:
2025-10-28 15:04:52 +01:00
parent ddb23b1da0
commit 807204869f

View File

@@ -139,12 +139,17 @@ runs:
f"port={os.environ['DATABASE_PORT']}"
)
for attempt in range(30):
try:
with psycopg2.connect(dsn):
break
except psycopg2.OperationalError:
time.sleep(2)
max_attempts = 30
for attempt in range(max_attempts):
try:
with psycopg2.connect(dsn):
break
except psycopg2.OperationalError as exc:
print(
f"Attempt {attempt + 1}/{max_attempts} failed to connect to Postgres: {exc}",
flush=True,
)
time.sleep(2)
else:
raise SystemExit("Postgres service did not become available")
PY