Skip to content

Workers

Partial

The server’s background work is everything that happens without a request waiting on it: landing telemetry, computing calc rules, sending notifications, settling commands, holding event rule streaks for their sustain, and pruning what has aged out. Two shapes carry it today. Telemetry arrives on the bus, so a JetStream consumer lands it. Everything else is born as a Postgres row, so a server tick drains it: a loop on a fixed interval. The ticks that claim work rows (calc marks, notifications, snoozes) claim them with FOR UPDATE SKIP LOCKED, so two servers against one database share the work, and a restart resumes where the last pass stopped.

The telemetry consumer is the one consumer built (messaging). It carries the exactly-once triple every consumer here is meant to share: the stream deduplicates a batch’s Nats-Msg-Id, the consumer double-acks, and the sink is idempotent, a batch’s receipt written in the batch’s own transaction (ADR-0311). It runs as one durable per partition of the outpost’s name, each holding one batch in flight, so an outpost’s batches land in order while the partitions land side by side (ADR-1896). Order matters for the property lane, whose transition guard compares a value with the series’ latest: a lock per series stops two batches writing one value twice, but cannot reorder them. A transient failure is redelivered after a growing delay, up to five deliveries; the consumer then gives the batch up and records why (accounting).

The rest runs on ticks, each a goroutine of its own in internal/bus or internal/notifier, so a slow pass of one never delays another:

TickEveryWhat it drains
calc1 sup to 500 pending calc marks a pass, each in its own transaction, oldest first (ADR-0148)
notification2 sthe queued notification rows an alarm transition wrote, and the snoozes past their deadline (ADR-0618, ADR-1318)
settlement5 scommands past their settle window, then event rule streaks held for their sustain (ADR-0144)
rule reconcile1 minevent rule state against the newest samples, healing a rare race; once at start too
check-in age15 severy claimed outpost’s checkin-age
orphan flush1 minthe orphaned-batch counts on each outpost row
receipt prune1 htelemetry receipts older than a day
sample retention1 hsamples past their retention window (storage)

A silent outpost produces no message, so its liveness is read rather than drained: the check-in age timer writes the seconds since each outpost last spoke, and the seeded outpost-silent rule reads that series like any other (ADR-1707).

There is no projector stage: a current value is read from the latest series row (storage), and alarm holds its own state. Two pieces of work are deliberately not background work. Health rolls up inside the transaction that changed it, since a rollup a hop later would record its transition at the wrong moment. Parsing happens at the edge (collection).

The axis that decides how a piece of work is written:

  • Stateless (owner resolution, calc): the output is a function of the input, the rules and a snapshot. Order does not matter, and the write is an append.
  • Stateful (the alarm lifecycle): state persists across inputs, so order matters. The alarm transition serializes per alarm identity, the raiser’s dedup_key (ADR-0075), and the write is a guarded upsert with a partial unique index as the backstop: alarm_open_identity_key allows one open alarm per component and dedup_key.

Every derived sample carries its lineage on the row: provenance says where it came from (observed, calculated, intended or declared), and a calculated row names its source_rule and the rule’s id, so its history outlives the rule (metrics and properties).

The consumer and the ticks report how they keep up on the server’s own platform component once a report window (#1628), beside the pipeline figures (messaging). Every failure count sits beside its attempts, so a loss reads as a ratio where 0 is healthy.

  • Calc: calc-pending-depth is the deepest the pending set stood at any pass in the window, marks still waiting out their debounce included; calc-served-count the marks the window’s passes computed; calc-pass-duration a pass’s mean milliseconds. Healthy is a depth that falls back toward 0 between bursts and a pass well under its second.
  • Notifications: outbox-queued-depth is the rows still queued at the window’s close, due or waiting out a retry backoff; outbox-due-age how long the oldest due row has waited past its send time, 0 when none is due. A failing webhook holds the depth up while the due age stays near 0, since a backoff is not a wait; a due age that grows says the sender is not reaching its rows.
  • Settlement: sweep-duration, sweep-count and sweep-failure-count, each at two instances, command-settlement and event-rule. A pass that succeeds writes its failure count as 0, so Platform health reads each sweep’s failures against its passes.

These read the server’s clock against its own database, so unlike ingest lag no outpost clock is in them (ADR-1628). The rules that alarm on the server itself, rule-sweep-stalled among them, are on self-monitoring.