Functional Weave
Code in TypeScript

monitor.heartbeat-check@1.0.0

impl/python.py

719 bytes · the Python implementation · view raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

from typing import Optional

from .monitor_check_status import CheckStatus  ← from monitor.check-status ^1.0.0 · built alongside by fune
from .monitor_heartbeat import HeartbeatState  ← from monitor.heartbeat ^1.0.0 · built alongside by fune

_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]