eventdispatch

package
v0.0.76 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Executor

type Executor interface {
	// ExecuteFunction executes a function with the given code and event.
	// It returns a result as a JSON-like map and any error encountered.
	ExecuteFunction(
		ctx context.Context,
		code string,
		functionName string,
		event *eventstore.Event,
	) (map[string]interface{}, error)
}

Executor defines the interface for executing functions with an event as input.

type FunctionWithTrigger

type FunctionWithTrigger struct {
	Function *functionstore.Function
	Trigger  *functionstore.EventTrigger
}

FunctionWithTrigger represents a function and its associated trigger.

type FunctionsHandler

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

FunctionsHandler manages the caching and execution of functions triggered by events. It maintains caches of functions and event triggers that are periodically synchronized.

func (*FunctionsHandler) GetFunctions

func (r *FunctionsHandler) GetFunctions(ctx context.Context, eventTypes ...string) (map[string][]*FunctionWithTrigger, error)

GetFunctions retrieves all functions associated with the given event types. It returns a mapping from event type to a list of function-trigger pairs.

func (*FunctionsHandler) HandleEvent

func (r *FunctionsHandler) HandleEvent(ctx context.Context, events ...*eventstore.Event)

HandleEvent processes incoming events and triggers any associated functions.

func (*FunctionsHandler) Sync

func (r *FunctionsHandler) Sync(ctx context.Context) error

Sync implements TriggerManager.

type Sync

type Sync interface {
	Sync(ctx context.Context) error
}

type Trigger

type Trigger interface {
	// HandleEvent processes one or more events and triggers any associated functions.
	HandleEvent(ctx context.Context, events ...*eventstore.Event)
}

Trigger defines the interface for handling events and executing associated functions.

type TriggerManager

type TriggerManager interface {
	Trigger
	Sync
}

func New

func New(
	ctx context.Context,
	functions functionservice.Service,
	onError func(context.Context, error),
	syncInterval time.Duration,
	fnexec Executor,
	tracker libtracker.ActivityTracker) (TriggerManager, error)

New creates a new FunctionsHandler instance with initial synchronization. It returns a Trigger implementation that can handle events.

Parameters:

  • ctx: Context for the initialization operations
  • functions: Service for retrieving functions and triggers
  • onError: Error handler callback
  • syncInterval: How often to synchronize with the function service
  • tracker: Activity tracker for monitoring (optional)

Jump to

Keyboard shortcuts

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