Documentation
¶
Overview ¶
Package events is the in-process event bus every integration reads: the API's event stream, the webhook dispatcher, and the per-job stream the web UI already had. Each event is a CloudEvents 1.0 envelope in the JSON format (https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/formats/json-format.md), so a receiver can use the tooling that format already has, and each type's data has a JSON Schema embedded in the binary.
The package imports nothing else from this module: publishers depend on it, never the other way round.
Index ¶
Constants ¶
const ( // JobStarted: a sync, sync-all, recipe or audit run began (web UI or API). JobStarted = "job.started" // JobProgress: a pipeline stage started, finished or failed. Stream only: // it is too frequent for a webhook, and the dispatcher refuses it. JobProgress = "job.progress" // JobFinished: a run ended, with its status. JobFinished = "job.finished" // PackSynced: one pack of a run refreshed from upstream. PackSynced = "pack.synced" // PackBehindUpstream: an upstream check found a pack behind. PackBehindUpstream = "pack.behind_upstream" // UpstreamChecked: an upstream check of every pack finished. UpstreamChecked = "upstream.checked" // ConfigChanged: a config file or setting was saved. It names the file // and the key, never the value. ConfigChanged = "config.changed" // ServerStarted and ServerStopping: the serve lifecycle. ServerStarted = "server.started" ServerStopping = "server.stopping" // WebhookDisabled: an endpoint was turned off after too many // consecutive failed deliveries. WebhookDisabled = "webhook.disabled" // WebhookTest: a test delivery asked for by `webhooks test` or the API. WebhookTest = "webhook.test" )
The v1 event types. A type is published by exactly the code named beside it; TestEveryTypeHasAPublisher fails on a type nothing publishes, and TestEveryTypeHasASchema on one with no schema.
const DefaultBuffer = 1000
DefaultBuffer is a subscriber's queue length. A subscriber that falls this far behind loses events, counted, rather than slowing a sync down.
const SpecVersion = "1.0"
SpecVersion is the CloudEvents version of every envelope.
Variables ¶
This section is empty.
Functions ¶
func NewID ¶
NewID returns a ULID (https://github.com/ulid/spec): 48 bits of milliseconds and 80 random bits, 26 characters, sortable by time.
func SchemaFiles ¶
func SchemaFiles() []string
SchemaFiles lists the embedded schema files' types, sorted.
func Source ¶
func Source() string
Source is this machine's event source, icon-sets-sync://<hostname>.
func StreamOnly ¶
StreamOnly reports whether t is sent on the event stream only, never to a webhook.
Types ¶
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus is a typed, in-process publish/subscribe bus. Publishing never blocks: a full subscriber drops the event and counts it.
func NewBus ¶
NewBus returns a bus whose events carry source (see Source). now is the clock; nil means time.Now.
func (*Bus) Emit ¶
Emit builds an event of typ with data and publishes it. An event that cannot be built (an unknown type, unencodable data) is a programming error: it is logged and dropped rather than taking a sync down with it.
type Event ¶
type Event struct {
SpecVersion string `json:"specversion"`
ID string `json:"id"`
Source string `json:"source"`
Type string `json:"type"`
Time time.Time `json:"time"`
DataContentType string `json:"datacontenttype"`
Data json.RawMessage `json:"data"`
}
Event is one CloudEvents 1.0 envelope.
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription is one consumer's queue.
func (*Subscription) C ¶
func (s *Subscription) C() <-chan Event
C delivers the events. It is closed by Close.
func (*Subscription) Dropped ¶
func (s *Subscription) Dropped() int64
Dropped counts the events lost because the queue was full.