Skip to content

Commit

Permalink
DB health provider should use Alchemy's do_ping instead of platform s…
Browse files Browse the repository at this point in the history
…pecific query

See #6
  • Loading branch information
michael.yak authored and michaelyaakoby committed Sep 7, 2021
1 parent 390a565 commit 9df1f02
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions pyctuator/health/db_health_provider.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import importlib.util
import time
from dataclasses import dataclass
from typing import Optional

Expand Down Expand Up @@ -34,16 +33,14 @@ def get_name(self) -> str:
return "db"

def get_health(self) -> DbHealthStatus:
expected = int(time.time() * 1000)
try:
res = self.engine.execute(f"SELECT {expected}")
actual = next(res)[0]
if expected == actual:
conn = self.engine.raw_connection()
if self.engine.dialect.do_ping(conn):
return DbHealthStatus(status=Status.UP, details=DbHealthDetails(self.engine.name))

return DbHealthStatus(
status=Status.UNKNOWN,
details=DbHealthDetails(self.engine.name, f"Selected {expected}, got {actual}"))
details=DbHealthDetails(self.engine.name, f"Pinging failed"))

except OperationalError as e:
except Exception as e: # pylint: disable=broad-except
return DbHealthStatus(status=Status.DOWN, details=DbHealthDetails(self.engine.name, str(e)))

0 comments on commit 9df1f02

Please sign in to comment.