Skip to content

Commit 9df1f02

Browse files
michael.yakmichaelyaakoby
authored andcommitted
DB health provider should use Alchemy's do_ping instead of platform specific query
See #6
1 parent 390a565 commit 9df1f02

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

pyctuator/health/db_health_provider.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import importlib.util
2-
import time
32
from dataclasses import dataclass
43
from typing import Optional
54

@@ -34,16 +33,14 @@ def get_name(self) -> str:
3433
return "db"
3534

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

4441
return DbHealthStatus(
4542
status=Status.UNKNOWN,
46-
details=DbHealthDetails(self.engine.name, f"Selected {expected}, got {actual}"))
43+
details=DbHealthDetails(self.engine.name, f"Pinging failed"))
4744

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

0 commit comments

Comments
 (0)