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