Skip to content

tdfs4ds.serve.health

tdfs4ds.serve.health

Is the database still there? A monitor for the admin app (0.3.7.4).

One daemon thread per app process asks the database SELECT 1 every TDFS4DS_SERVE_HEALTH_INTERVAL seconds (default 60, 0 = off), on its own raw teradatasql connection built from the same TDFS4DS_TD_* variables as reconnect._connect_kwargs(). It never touches teradataml's shared connection: a probe on that connection, while a panel is using it, is what broke the app before (see activity). The connection is kept open between ticks and reopened after a failure.

States of snapshot()["state"]:

  • connected - the probe answered (latency_ms, last_ok).
  • lost - transport error or timeout: the database is not reachable.
  • refused - the logon was refused (Error 8017 / SQLState 28000: expired token, wrong password).
  • unknown - nothing to probe with (no TDFS4DS_TD_* credentials in the environment) or not probed yet. The shared connection is not used as a fallback.

On connected -> lost/refused the app's CONNECTED flag goes False with the reason in LAST_CONNECT_ERROR, so every panel shows it. On lost -> connected the teradataml context is restored with reconnect_teradata(), but only when no background job runs (a job holds statements on the shared connection); otherwise reconnect_pending is set and the next tick tries again. reconnect_now() is the same path for the status bar's button.

The monitor also runs the periodic configuration checks (config_checks).

logger module-attribute

logger = getLogger(__name__)

DEFAULT_INTERVAL_S module-attribute

DEFAULT_INTERVAL_S = 60.0

PROBE_TIMEOUT_S module-attribute

PROBE_TIMEOUT_S = 10

_LOCK module-attribute

_LOCK = RLock()

_RECONNECT_LOCK module-attribute

_RECONNECT_LOCK = Lock()

_STOP module-attribute

_STOP = Event()

_THREAD module-attribute

_THREAD: Optional[Thread] = None

_CONN module-attribute

_CONN = None

_STATE module-attribute

_STATE: dict = {}

_TIMEOUT_MARKERS module-attribute

_TIMEOUT_MARKERS = ('timed out', 'timeout', 'time out', 'request timeout')

OPEN module-attribute

OPEN: Callable = _default_open

_reset_state

_reset_state() -> None

interval_seconds

interval_seconds() -> float

TDFS4DS_SERVE_HEALTH_INTERVAL as seconds; 0 = disabled; a bad value = default.

enabled

enabled() -> bool

_now_iso

_now_iso() -> str

classify_error

classify_error(exc: BaseException) -> tuple

('refused' | 'lost', detail) for a failure of the probe.

Refused only when the database answered and said no (the markers reconnect_teradata already uses); everything else that kept the probe from getting an answer is a lost connection. The detail is the whole message without the driver's Go frames.

_default_open

_default_open(kwargs)

_credentials

_credentials()

_close_probe

_close_probe() -> None

probe_once

probe_once() -> dict

One probe. Returns {'state', 'detail', 'latency_ms'}; never raises.

_jobs_running

_jobs_running() -> bool

_mark_app_disconnected

_mark_app_disconnected(reason: str) -> None

reconnect_now

reconnect_now(manual: bool = False, full: bool = False) -> dict

Restore teradataml's context. {'ok', 'status', 'pending'}; never raises.

Refused while a background job runs: the job holds statements on the shared connection, and replacing it under them is what corrupted the app before. A manual call says so; the automatic one leaves reconnect_pending set and retries on the next tick.

apply_result

apply_result(result: dict) -> None

Record a probe and act on the transition.

tick

tick() -> dict

One monitor step: probe, apply, and the periodic configuration checks.

_loop

_loop() -> None

start

start() -> bool

Start the monitor thread (once). False when disabled or already running.

stop

stop(timeout: float = 3.0) -> None

_token_info

_token_info() -> Optional[dict]

snapshot

snapshot() -> dict