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 ¶
const DefaultConsumer = "eventtrigger.dispatcher"
DefaultConsumer is the cursor name the CLI dispatcher runs under.
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.
const FilePrefix = "trigger-"
FilePrefix marks a file as a trigger definition (trigger-*.json).
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 ¶
IsTriggerFile reports whether base names a trigger definition file.
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.
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 ¶
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 ¶
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.