def do_GET_liveness(self) -> None:
        """Handle a ``GET`` request to ``/liveness`` path.

        Write a simple HTTP response with HTTP status:

            * ``200``:

                * If the cluster is in maintenance mode; or
                * If Patroni heartbeat loop is properly running;

            * ``503``:

                * if Patroni heartbeat loop last run was more than ``ttl`` setting ago on the primary (or twice the
                    value of ``ttl`` on a replica).

        """
        patroni: Patroni = self.server.patroni
        is_primary = patroni.postgresql.role == PostgresqlRole.PRIMARY and patroni.postgresql.is_running()
        # We can tolerate Patroni problems longer on the replica.
        # On the primary the liveness probe most likely will start failing only after the leader key expired.
        # It should not be a big problem because replicas will see that the primary is still alive via REST API call.
        liveness_threshold = patroni.dcs.ttl * (1 if is_primary else 2)

        # In maintenance mode (pause) we are fine if heartbeat loop stuck.
        status_code = 200 if patroni.ha.is_paused() or patroni.next_run + liveness_threshold > time.time() else 503
        self._write_status_code_only(status_code)
Handle a ``GET`` request to ``/liveness`` path.

        Write a simple HTTP response with HTTP status:

            * ``200``:

                * If the cluster is in maintenance mode; or
                * If Patroni heartbeat loop is properly running;

            * ``503``:

                * if Patroni heartbeat loop last run was more than ``ttl`` setting ago on the primary (or twice the
                    value of ``ttl`` on a replica).

        
patroni/api.py