eventtriggers

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package eventtriggers provides event-driven workflow triggers. It lets workflows subscribe to domain events via HTTP API, evaluates filter expressions, and automatically starts workflow instances when matching events are published.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EvaluateFilter

func EvaluateFilter(expr string, eventData map[string]any) (bool, error)

EvaluateFilter evaluates a filter against event data. It accepts two forms:

  1. Structured JSON filter (when expr starts with '{'): {"event.data.amount": {"$gt": 100}, "event.data.status": {"$in": ["active","pending"]}}
  2. Text expression (otherwise): event.data.amount > 100

If the expression is empty or "true", returns true without evaluation.

func New

func New() plugin.Plugin

New creates a new Plugin instance.

func PublishEvent

func PublishEvent(
	ctx context.Context,
	db plugin.PluginDB,
	logger *slog.Logger,
	env *plugin.Environment,
	eventID uuid.UUID,
	tenantID uuid.UUID,
	eventType string,
	eventData map[string]any,
) (int, error)

PublishEvent stores an event, dispatches it to matching subscriptions, and signals any workflows awaiting this event type. Returns the number of workflows started.

This is the core publishing pipeline, exported so that other plugins (e.g., kafkaconnect, webhookingest) can publish events without going through the HTTP API.

Types

type Plugin

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

Plugin implements event-driven workflow triggers with tenant-isolated event subscriptions, idempotent event ingestion, and filter expressions.

func (*Plugin) Info

func (p *Plugin) Info() plugin.PluginInfo

Info returns plugin metadata for discovery and documentation.

func (*Plugin) Init

func (p *Plugin) Init(ctx context.Context, env *plugin.Environment) error

Init initializes the plugin with the given environment.

func (*Plugin) Migrations

func (p *Plugin) Migrations() []plugin.Migration

Migrations returns the database schema for event subscription management and event storage. Tables are idempotent (IF NOT EXISTS) and safe to run multiple times.

func (*Plugin) RegisterHostFunctions

func (p *Plugin) RegisterHostFunctions(scope plugin.FuncRegistry) error

RegisterHostFunctions registers workflow-callable functions on the scoped function registry under the "event-triggers" plugin namespace.

func (*Plugin) RegisterRoutes

func (p *Plugin) RegisterRoutes(mux *http.ServeMux) error

RegisterRoutes registers HTTP handlers for the event-triggers plugin.

func (*Plugin) Run

func (p *Plugin) Run(ctx context.Context) error

Run starts the background retry worker loop. It periodically queries ingested_events for unprocessed events that are at least 10 seconds old and retries their workflow dispatch. Returns when ctx is cancelled.

Jump to

Keyboard shortcuts

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