From 807204869fefeb1821a7d7d6037862655649e047 Mon Sep 17 00:00:00 2001 From: zwitschi Date: Tue, 28 Oct 2025 15:04:52 +0100 Subject: [PATCH] fix: Improve database connection retry logic with detailed error messages --- .gitea/actions/setup-python-env/action.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.gitea/actions/setup-python-env/action.yml b/.gitea/actions/setup-python-env/action.yml index 3ad1a66..b9d89c0 100644 --- a/.gitea/actions/setup-python-env/action.yml +++ b/.gitea/actions/setup-python-env/action.yml @@ -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