engine

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package engine provides the execution orchestration layer for function execution.

The engine package separates concerns between:

  • HTTP handling (in the api package)
  • Execution orchestration (this package)
  • Language-specific execution (runtime implementations)

Architecture

The engine package defines two main interfaces:

Runtime: Implemented by language-specific executors (Lua, JavaScript, etc.) that handle the actual code execution.

Engine: Orchestrates the complete execution lifecycle including:

  • Function and version retrieval
  • Execution record management
  • Event masking for storage
  • Runtime invocation
  • Status tracking and duration measurement

Usage

Create an engine with all required dependencies:

eng := engine.New(engine.Config{
    DB:           db,
    Runtime:      luaRuntime,
    Logger:       logger,
    // ... other dependencies
})

Execute a function:

result, err := eng.Execute(ctx, engine.ExecutionRequest{
    FunctionID: "my-function",
    Event:      httpEvent,
    Trigger:    store.ExecutionTriggerHTTP,
})

Index

Constants

View Source
const MaxResponseBodySize = 1024 * 1024

MaxResponseBodySize is the maximum size of response body to store (1MB)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	DB               store.DB
	Runtime          Runtime
	Logger           logger.Logger
	KVStore          kv.Store
	EnvStore         env.Store
	HTTPClient       http.Client
	AIClient         ai.Client
	AITracker        ai.Tracker
	EmailClient      email.Client
	EmailTracker     email.Tracker
	ExecutionTimeout time.Duration
	IDGenerator      func() string
}

Config holds all dependencies needed to create an engine.

type DefaultEngine

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

DefaultEngine is the default implementation of the Engine interface.

func New

func New(cfg Config) *DefaultEngine

New creates a new DefaultEngine with the given configuration.

func (*DefaultEngine) Execute

Execute runs a function with full lifecycle management.

type Engine

type Engine interface {
	// Execute runs a function with the given request and returns the result.
	Execute(ctx context.Context, req ExecutionRequest) (*ExecutionResult, error)
}

Engine orchestrates function execution with full lifecycle management.

type ExecutionRecordError

type ExecutionRecordError struct {
	Err error
}

ExecutionRecordError indicates a failure to create/update execution record.

func (*ExecutionRecordError) Error

func (e *ExecutionRecordError) Error() string

func (*ExecutionRecordError) Unwrap

func (e *ExecutionRecordError) Unwrap() error

type ExecutionRequest

type ExecutionRequest struct {
	// FunctionID is the unique identifier of the function to execute
	FunctionID string

	// Event is the trigger event (HTTP request, cron trigger, etc.)
	Event events.Event

	// Trigger indicates how the execution was triggered (HTTP, cron, etc.)
	Trigger store.ExecutionTrigger

	// BaseURL is the base URL of the server for generating function URLs
	BaseURL string
}

ExecutionRequest contains all information needed to execute a function.

type ExecutionResult

type ExecutionResult struct {
	// ExecutionID is the unique identifier for this execution
	ExecutionID string

	// FunctionVersionID is the ID of the function version that was executed
	FunctionVersionID string

	// Response is the HTTP response from the function (for HTTP events)
	Response *events.HTTPResponse

	// Duration is how long the execution took
	Duration time.Duration

	// Status indicates whether execution succeeded or failed
	Status store.ExecutionStatus

	// Error contains the error if execution failed
	Error error
}

ExecutionResult contains the outcome of a function execution.

type FunctionDisabledError

type FunctionDisabledError struct {
	FunctionID string
}

FunctionDisabledError indicates the function is disabled.

func (*FunctionDisabledError) Error

func (e *FunctionDisabledError) Error() string

type FunctionNotFoundError

type FunctionNotFoundError struct {
	FunctionID string
}

FunctionNotFoundError indicates the requested function does not exist.

func (*FunctionNotFoundError) Error

func (e *FunctionNotFoundError) Error() string

type NoActiveVersionError

type NoActiveVersionError struct {
	FunctionID string
}

NoActiveVersionError indicates no active version exists for the function.

func (*NoActiveVersionError) Error

func (e *NoActiveVersionError) Error() string

type Runtime

type Runtime interface {
	// Execute runs the provided code with the given context and event.
	// It returns the execution result or an error if execution failed.
	Execute(ctx context.Context, req RuntimeRequest) (*RuntimeResult, error)
}

Runtime is the interface for language-specific code executors. Implementations handle the actual execution of function code in a specific language runtime (Lua, JavaScript, Python, etc.).

type RuntimeRequest

type RuntimeRequest struct {
	// Code is the function source code to execute
	Code string

	// Context provides execution metadata (function ID, execution ID, etc.)
	Context *events.ExecutionContext

	// Event is the trigger event (HTTP request, cron trigger, etc.)
	Event events.Event
}

RuntimeRequest contains all information needed to execute function code.

type RuntimeResult

type RuntimeResult struct {
	// Response is the HTTP response from the function (for HTTP events)
	Response *events.HTTPResponse
}

RuntimeResult contains the output from executing function code.

Jump to

Keyboard shortcuts

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