eventbus

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package eventbus is loom-server's in-memory observability fan-out. Every notable side-effect of the server (and the SPA, via POST /api/events/client) flows through here ; the DoctorPanel SSE stream at /api/events tails the bus so operators can watch what's happening end-to-end without grepping logs across processes.

Design : single Hub, slog.Handler-shaped Publish, lossy subscribers with a per-sub bounded ring buffer. A slow doctor browser doesn't hold the WS sync write path hostage ; if a subscriber falls behind past `slow` events the dropper increments a counter and the SSE emits a synthetic "<drop>" line so the operator knows they're missing context. Same shape as weft-doctor in the cluster — one less concept to learn when jumping between weft and weft-loom.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	TS        time.Time      `json:"ts"`
	Source    string         `json:"source"` // "server" or "client"
	Component string         `json:"component"`
	Verb      string         `json:"verb"`
	Level     string         `json:"level"` // "debug" | "info" | "warn" | "error"
	Message   string         `json:"message,omitempty"`
	Fields    map[string]any `json:"fields,omitempty"`
	// Project identifies the project the event relates to ; the
	// doctor UI filters on this so two operators in different
	// projects don't drown each other.
	Project string `json:"project,omitempty"`
}

Event is the wire shape. Component + verb identify the producer + the action ; level matches slog ; Fields holds the structured payload (anything JSON-serialisable).

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

Hub fans out events to N subscribers. Created at boot, retained for the loom-server's lifetime. Concurrent Publish + Subscribe + Unsubscribe safe.

func New

func New() *Hub

New : Hub ready for Subscribe + Publish.

func (*Hub) Close

func (h *Hub) Close()

Close stops further publishes. Subscribers receive a final closed channel when they call their stop fn.

func (*Hub) Drops

func (h *Hub) Drops() uint64

Drops returns the lifetime drop counter ; doctor UI surfaces this in the "Diagnostics" header so an operator sees buffer pressure before symptoms.

func (*Hub) Publish

func (h *Hub) Publish(ev Event)

Publish fan-outs to every subscriber. Non-blocking : drops events when a subscriber buffer is full.

func (*Hub) PublishCtx

func (h *Hub) PublishCtx(_ context.Context, ev Event)

PublishCtx is the same as Publish but tagged with the deadline origin ; the doctor UI surfaces request-scoped events as a thread.

func (*Hub) Subscribe

func (h *Hub) Subscribe() (<-chan Event, func())

Subscribe returns an unbuffered receive channel + an unregister fn. Caller MUST drain the channel ; once subBuffer events queue up the next publish drops the oldest and emits a "<drop>" sentinel via the overflow counter (visible to the SSE handler).

func (*Hub) SubscribeWithDrops

func (h *Hub) SubscribeWithDrops() (<-chan Event, <-chan Event, func())

SubscribeWithDrops returns the regular Event channel plus a drop-marker channel (capacity 1, drop-on-full) that publishes a single Event{Verb: "drop", Fields: {"drops": N}} sentinel whenever the regular channel overflows. Callers that want to surface buffer-pressure to operators (e.g. the doctor SSE stream) select on both ; everyone else uses Subscribe.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL