fix: Improve database connection retry logic with detailed error messages
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user