1
0
mirror of https://github.com/quay/quay.git synced 2026-01-29 08:42:15 +03:00
Files
quay/data/model/health.py
Jonathan King c36945b836 healthcheck: Use db_kwargs in health check (PROJQUAY-4222) (#1507)
- The database health check is currently not using the db_kwargs and not using ssl settings
- This is causing health check failures for MySQL behind SSL
2022-08-31 14:20:56 -04:00

26 lines
948 B
Python

import logging
from data.database import TeamRole, validate_database_url
logger = logging.getLogger(__name__)
def check_health(app_config):
# Attempt to connect to the database first. If the DB is not responding,
# using the validate_database_url will timeout quickly, as opposed to
# making a normal connect which will just hang (thus breaking the health
# check).
try:
validate_database_url(
app_config["DB_URI"], app_config["DB_CONNECTION_ARGS"], connect_timeout=3
)
except Exception as ex:
return (False, "Could not connect to the database: %s" % str(ex))
# We will connect to the db, check that it contains some team role kinds
try:
okay = bool(list(TeamRole.select().limit(1)))
return (okay, "Could not connect to the database" if not okay else None)
except Exception as ex:
return (False, "Could not connect to the database: %s" % str(ex))