events

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 14 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 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

View Source
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.

View Source
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.

View Source
const SpecVersion = "1.0"

SpecVersion is the CloudEvents version of every envelope.

Variables

This section is empty.

Functions

func Known

func Known(t string) bool

Known reports whether t is an event type.

func NewID

func NewID(now time.Time) string

NewID returns a ULID (https://github.com/ulid/spec): 48 bits of milliseconds and 80 random bits, 26 characters, sortable by time.

func Schema

func Schema(typ string) ([]byte, bool)

Schema returns the JSON Schema of a type's data.

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

func StreamOnly(t string) bool

StreamOnly reports whether t is sent on the event stream only, never to a webhook.

func Types

func Types() []string

Types returns every event type, in display order.

func Validate

func Validate(e Event) error

Validate checks an event's envelope and its data against the type's schema.

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

func NewBus(source string, now func() time.Time) *Bus

NewBus returns a bus whose events carry source (see Source). now is the clock; nil means time.Now.

func (*Bus) Emit

func (b *Bus) Emit(typ string, data any)

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.

func (*Bus) Publish

func (b *Bus) Publish(e Event)

Publish hands e to every subscriber whose filter admits it.

func (*Bus) Subscribe

func (b *Bus) Subscribe(buffer int, types ...string) *Subscription

Subscribe returns a subscription to the given types (none means every type), with a queue of buffer events (DefaultBuffer when below 1).

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.

func New

func New(source, typ string, now time.Time, data any) (Event, error)

New builds an envelope. data is marshalled as JSON.

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) Close

func (s *Subscription) Close()

Close stops delivery and closes C.

func (*Subscription) Dropped

func (s *Subscription) Dropped() int64

Dropped counts the events lost because the queue was full.

Jump to

Keyboard shortcuts

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