events

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package events is the in-process event hub. The pipeline, the action executor and the account supervisors publish; the HTTP layer subscribes and writes each event to its Server-Sent Events stream. It lives outside internal/api so publishers need not import the HTTP layer.

Index

Constants

View Source
const (
	MessageProcessed = "message.processed" // Data: store.ActivityRow
	MessageReview    = "message.review"    // Data: store.ActivityRow
	ActionUndone     = "action.undone"     // Data: store.Action
	AccountStatus    = "account.status"    // Data: store.Account
	BatchProgress    = "batch.progress"
	CheckProgress    = "check.progress" // a cleanup check moved forward or ended; Data: worker.CheckState (rows omitted)
	RulesChanged     = "rules.changed"
	UsageUpdated     = "usage.updated" // Data: nil
)

Event names, as sent in the SSE "event:" field.

View Source
const Keep = 200

Keep is how many past events a reconnecting subscriber can replay.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	ID   int64
	Name string
	Data any
}

Event is one published event. IDs grow by one per event and restart with the daemon. Data is the Go value; the HTTP layer chooses its JSON shape.

type Hub

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

Hub fans events out to subscribers and remembers the last Keep. A nil *Hub drops everything, so publishers need no nil checks.

func NewHub

func NewHub() *Hub

NewHub returns an empty hub.

func (*Hub) Publish

func (h *Hub) Publish(name string, data any)

Publish stores the event and hands it to every subscriber. It never blocks: a subscriber that has fallen subBuffer events behind is dropped (its channel closes) and catches up by subscribing again with the last id it saw.

func (*Hub) Subscribe

func (h *Hub) Subscribe(lastID int64) (missed []Event, live <-chan Event, cancel func())

Subscribe returns the kept events with an id above lastID (the client's Last-Event-ID; 0 for a new client replays nothing), then a channel of everything published afterwards. A lastID from before a daemon restart is ahead of the hub and replays everything kept. cancel ends the subscription and may be called more than once.

Jump to

Keyboard shortcuts

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