Added healthcheck
This commit is contained in:
@ -7,6 +7,7 @@ from sqlalchemy.exc import DatabaseError
|
||||
import time
|
||||
from werkzeug.security import generate_password_hash
|
||||
|
||||
db_ready = False
|
||||
|
||||
def admin_required(user_id, message='Access denied.'):
|
||||
"Check if common user try to make administrative action."
|
||||
@ -33,10 +34,12 @@ def get_user_or_404(user_id):
|
||||
|
||||
def wait_for_db(max_retries):
|
||||
"Try to connect with database <max_retries> times."
|
||||
global db_ready
|
||||
for _ in range(max_retries):
|
||||
try:
|
||||
with db.engine.connect() as connection:
|
||||
connection.execute(text("SELECT 1"))
|
||||
db_ready = True
|
||||
return
|
||||
except DatabaseError:
|
||||
time.sleep(3)
|
||||
|
Reference in New Issue
Block a user