from typing import Optional from .monitor_check_status import CheckStatus from .monitor_heartbeat import HeartbeatState _STATUS = {"up": "up", "late": "degraded", "down": "down"} def heartbeat_check(state: HeartbeatState) -> Optional[CheckStatus]: """A heartbeat as one check behind a status page component. Late is degraded, not down: the job may still ping within its grace time, which is what the grace time is for. A new heartbeat has proved nothing either way, so it is null rather than a guess.""" if state == "new": return None if state not in _STATUS: raise ValueError("unknown heartbeat state: %s" % (state,)) return _STATUS[state] # type: ignore[return-value]