Skip to main content

Feedback

portholeView

Decides what the status spot shows, as a pure function of the service's snapshot, its last heartbeat and this clock, so a window, a CLI and a test reach the same answer.

import { portholeView } from "@/lib/ouro/porthole-view";

Example

const view = portholeView(source.getSnapshot(), source.lastBeatAt(), Date.now());
view.text; // "Up to date"

Usage

One item at a time: the most urgent (action, then error, working, rest); on a tie, the newest since. At rest it says "Up to date" only while every area was verified within freshWithinMs (the area's own, for one the service reads on an interval) and none has been in trouble for troubleAfterMs; otherwise the real age of the area verified longest ago ("Updated 4 min ago"). A rest item, such as "Version 2.1 is installed", shows over "Up to date" only: past fresh, or unknown, the age line or "Status unknown" wins and the item waits in the open spot's lines; shown with an action, it reads as action, since the person has something to press. It says "Status unknown" when an area has never been verified, when the snapshot has no areas or another version, or when the heartbeat is older than heartbeatTimeoutMs or too far ahead of this clock to check. A stopped heartbeat outranks every item, an action too: nothing the service said can be trusted as live, and the action's button would reach a service that cannot answer, so the item waits in the open spot's lines. nextChangeAt is the one moment to look again.

Use instead when

  • Use portholeStatus instead for the JSON an agent or a CLI reads, and the Porthole component to show it.

Parameters

snapshot
Type: PortholeSnapshot
heartbeatAt
Type: number
now
Type: number
options
Type: PortholeViewOptions
{}

Returns

PortholeView