Improved function body

This commit is contained in:
Marcin-Ramotowski
2025-06-11 19:57:15 +00:00
parent d3d3c98f99
commit dd9e9ce110
2 changed files with 4 additions and 9 deletions

View File

@ -30,20 +30,15 @@ def get_user_or_404(user_id):
return user
MAX_RETRIES = 100
def wait_for_db():
for retries in range(MAX_RETRIES):
def wait_for_db(max_retries):
for _ in range(max_retries):
try:
with db.engine.connect() as connection:
connection.execute(text("SELECT 1"))
print("Successfully connected with database.")
return
except DatabaseError:
print(f"Waiting for database... (retry {retries + 1})")
time.sleep(3)
print("Failed to connect to database.")
raise Exception("Database not ready after multiple retries.")
raise Exception("Failed to connect to database.")
def init_db():