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 ¶
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.
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 ¶
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 (*Hub) Publish ¶
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 ¶
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.