Skip to content

Commit

Permalink
Fix generator function
Browse files Browse the repository at this point in the history
  • Loading branch information
ibazulic committed Sep 16, 2024
1 parent 5377eef commit 8646695
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions data/model/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
def sql_timeout(app_config, database, timeout):
# Apply the context manager only if PostgreSQL is used as db schema
if "postgresql" in app_config["DB_URI"]:
database.execute_sql("SET statement_timeout=%s", (timeout,))
logger.debug("Checking for existence of team roles, timeout 5000 ms.")
database.execute_sql("SET statement_timeout=%s;", (timeout,))
try:
yield database
finally:
database.execute_sql("SET statement_timeout=0")
database.execute_sql("SET statement_timeout=%s;", (0,))
else:
pass
logger.debug("Checking for existence of team roles.")
try:
yield database
finally:
pass


def check_health(app_config):
Expand All @@ -35,7 +40,6 @@ def check_health(app_config):
# We will connect to the db, check that it contains some team role kinds
try:
with sql_timeout(app_config, db, 5000):
logger.debug("Checking for existence of team roles, timeout 5000 ms.")
okay = bool(list(TeamRole.select().limit(1)))
return (okay, "Could not execute query, timeout reached" if not okay else None)
except Exception as ex:
Expand Down

0 comments on commit 8646695

Please sign in to comment.