eventtrigger

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package eventtrigger routes durable events to the task chains operators configured to react to them, declared in trigger-*.json files. The dispatcher keeps an NID cursor for catch-up, a firings table for dedup, and a hop guard against loops. Execution is pluggable via ChainRunner; this package runs no chains.

Index

Constants

View Source
const DefaultConsumer = "eventtrigger.dispatcher"

DefaultConsumer is the cursor name the CLI dispatcher runs under.

View Source
const DefaultMaxHop = 4

DefaultMaxHop is the dispatch-loop budget: an event whose hop exceeds it is refused, never fired. A trigger chain's own events carry hop+1, so a self-feeding trigger dies out after this many generations.

View Source
const FilePrefix = "trigger-"

FilePrefix marks a file as a trigger definition (trigger-*.json).

View Source
const TriggerTypeFireChain = "fire_chain"

TriggerTypeFireChain is the only trigger action type: run a named chain with the firing event as input.

Variables

This section is empty.

Functions

func IsTriggerFile

func IsTriggerFile(base string) bool

IsTriggerFile reports whether base names a trigger definition file.

func Vet

func Vet(data []byte, resolve func(name string) error) error

Vet validates a trigger document's shape. resolve, when non-nil, must report whether a referenced system file (chain, policy) is resolvable — its error is surfaced verbatim.

Types

type ChainRunner

type ChainRunner interface {
	RunChain(ctx context.Context, t Trigger, ev runtimetypes.Event) error
}

ChainRunner executes one trigger's chain against one event. The context carries the firing's request ID and the incremented hop, which implementations must thread into the execution. A returned error never stops the dispatch loop.

type Deps

type Deps struct {
	Log   eventlog.Service
	Store runtimetypes.EventFiringStore
	// WorkspaceID scopes the drain: one workspace's triggers never fire on
	// another's events.
	WorkspaceID string
	Triggers    []Trigger
	Runner      ChainRunner
	Tracker     libtracker.ActivityTracker
	// OnFiring observes every recorded firing outcome (the CLI's one line per
	// firing). err is nil on runtimetypes.EventFiringStatusOK.
	OnFiring func(t Trigger, ev runtimetypes.Event, status, requestID string, err error)
	Consumer string
	MaxHop   int
	// Poll is the backstop drain interval; live bus deliveries only shorten
	// the wait, they are never load-bearing.
	Poll  time.Duration
	Batch int
}

Deps are the dispatcher's collaborators. Log, Store, Runner, and WorkspaceID are required; the rest defaults (Tracker to Noop, Consumer to DefaultConsumer, MaxHop to DefaultMaxHop, Poll to 2s, Batch to 256).

type Dispatcher

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

Dispatcher is a durable named consumer over the event log: on Run it catches up from its cursor, then live-tails the bus, deduping both paths through the (trigger, nid) claim in the firings table.

func New

func New(deps Deps) (*Dispatcher, error)

New validates deps and builds a Dispatcher.

func (*Dispatcher) Run

func (d *Dispatcher) Run(ctx context.Context) error

Run loads the cursor, drains the backlog, then tails live deliveries and the poll tick until ctx is cancelled. Returns nil on cancellation.

type Handler

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

Handler is the in-process trigger dispatch: a host that runs an engine mounts it on the event append seam so matching triggers fire live in the appending process. It shares firingCore with the Dispatcher and writes the same event_firings claims, so neither double-fires a (trigger, nid) pair.

func NewHandler

func NewHandler(deps Deps) (*Handler, error)

NewHandler validates deps and builds the in-process handler. Deps.Log, Poll, and Batch are unused (live-only, no drain).

func (*Handler) HandleEvent

func (h *Handler) HandleEvent(ctx context.Context, events ...*runtimetypes.Event)

HandleEvent fires every trigger matching each event, claim-first through the shared firings table. Events of another workspace are skipped, and no error propagates.

type Listener

type Listener struct {
	Type string `json:"type"`
}

Listener names the exact event type a trigger reacts to.

type LoadResult

type LoadResult struct {
	Triggers []Trigger
	Skipped  []SkippedFile
}

LoadResult reports one Load pass: the triggers that loaded and the files that did not (with the reason each was skipped).

func Load

func Load(ctx context.Context, tracker libtracker.ActivityTracker, roots ...string) (LoadResult, error)

Load walks roots in precedence order for trigger-*.json files and returns the valid triggers. An earlier root shadows a later one by basename, and a duplicate trigger name keeps the first definition. Malformed files are skipped.

func LoadKept

func LoadKept(ctx context.Context, tracker libtracker.ActivityTracker, keep func(string) bool, roots ...string) (LoadResult, error)

LoadKept is Load restricted to trigger names keep allows; a nil keep keeps every candidate. The gate `contenox`'s composition uses: without opt-in-beta keep refuses everything, so no trigger loads at all.

type SkippedFile

type SkippedFile struct {
	Path   string
	Reason string
}

SkippedFile is one trigger file Load refused, and why.

type Trigger

type Trigger struct {
	Name        string   `json:"name"`
	Description string   `json:"description,omitempty"`
	ListenFor   Listener `json:"listen_for"`
	Type        string   `json:"type"`
	Chain       string   `json:"chain"`
	Policy      string   `json:"policy,omitempty"`
}

Trigger binds an event type to a chain. Chain and Policy are file names resolved through the system-file lookup (workspace first, home fallback) at fire time, never absolute paths.

Jump to

Keyboard shortcuts

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