fix: Improve database connection retry logic with detailed error messages
This commit is contained in:
@@ -139,11 +139,16 @@ runs:
|
|||||||
f"port={os.environ['DATABASE_PORT']}"
|
f"port={os.environ['DATABASE_PORT']}"
|
||||||
)
|
)
|
||||||
|
|
||||||
for attempt in range(30):
|
max_attempts = 30
|
||||||
|
for attempt in range(max_attempts):
|
||||||
try:
|
try:
|
||||||
with psycopg2.connect(dsn):
|
with psycopg2.connect(dsn):
|
||||||
break
|
break
|
||||||
except psycopg2.OperationalError:
|
except psycopg2.OperationalError as exc:
|
||||||
|
print(
|
||||||
|
f"Attempt {attempt + 1}/{max_attempts} failed to connect to Postgres: {exc}",
|
||||||
|
flush=True,
|
||||||
|
)
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
else:
|
else:
|
||||||
raise SystemExit("Postgres service did not become available")
|
raise SystemExit("Postgres service did not become available")
|
||||||
|
|||||||
Reference in New Issue
Block a user