engine

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LevelInfo    = logging.LevelInfo
	LevelWarning = logging.LevelWarning
	LevelError   = logging.LevelError
	LevelDebug   = logging.LevelDebug
)

Variables

View Source
var (
	ErrFunctionNotLoaded    = errors.New("function not loaded")
	ErrEngineNotInitialized = errors.New("engine not initialized")
)

EngineError base errors

Functions

func DomainErrorToStatusCode added in v0.1.1

func DomainErrorToStatusCode(err *domainerrors.DomainError) int

func GetFunctionKey added in v0.1.1

func GetFunctionKey(namespace, name string) string

func IsNotFoundError

func IsNotFoundError(err error) bool

func NewBadRequestError

func NewBadRequestError(message string) error

NewBadRequestError is returned for invalid requests with the given message.

func NewInternalServerError

func NewInternalServerError(message string, err ...error) error

func NewNotFoundError

func NewNotFoundError(message string) error

func WrapEngineError

func WrapEngineError(message string, err error) error

Types

type BuildOperations added in v0.1.1

type BuildOperations interface {
	// BuildFunction builds a function from source and adds it to the registry.
	BuildFunction(namespace, name, path, tag string, config manifest.FunctionManifest) (*types.BuildResult, error)

	// ReassignTag changes a tag to point to a different digest.
	ReassignTag(namespace, name, tag, newDigest string) error
}

type CircuitBreaker

type CircuitBreaker = components.CircuitBreaker

type CircuitBreakerManager

type CircuitBreakerManager = components.CircuitBreakerManager

type Engine

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

func NewEngineWithConfig

func NewEngineWithConfig(cfg *config.Config, logger logging.Logger) (*Engine, error)

NewEngineWithConfig creates a new engine instance using a configuration object.

func NewEngineWithOptions

func NewEngineWithOptions(socketPath, httpAddr string, registryDir string,
	logger logging.Logger, options *Options) (*Engine, error)

NewEngineWithOptions creates a new engine instance with custom settings. Accepts optional logger and options parameters (nil values use defaults).

func (*Engine) BuildFunction

func (e *Engine) BuildFunction(namespace, name, path, tag string, config manifest.FunctionManifest) (*types.BuildResult, error)

BuildFunction builds a function and stores it in the registry.

func (*Engine) CallFunctionWithContext

func (e *Engine) CallFunctionWithContext(ctx context.Context, namespace, name, entrypoint string, payload []byte) ([]byte, error)

CallFunctionWithContext calls a function with the specified parameters.

func (*Engine) GetConfig

func (e *Engine) GetConfig() *config.Config

func (*Engine) GetRegistry

func (e *Engine) GetRegistry() registry.Registry

GetRegistry returns the registry instance. This is a convenience method for direct access when needed.

func (*Engine) IsFunctionStopped

func (e *Engine) IsFunctionStopped(namespace, name string) bool

IsFunctionStopped checks if a function is explicitly stopped.

func (*Engine) IsLoaded

func (e *Engine) IsLoaded(namespace, name string) bool

IsLoaded checks if a function is currently loaded.

func (*Engine) LoadFunctionWithContext

func (e *Engine) LoadFunctionWithContext(ctx context.Context, namespace, name, identifier string, config map[string]string) error

LoadFunctionWithContext loads a function with the specified identifier and configuration.

func (*Engine) LoadFunctionWithForce

func (e *Engine) LoadFunctionWithForce(ctx context.Context, namespace, name, identifier string, config map[string]string, force bool) error

LoadFunctionWithForce loads a function with the option to force loading even if stopped.

func (*Engine) ReassignTag

func (e *Engine) ReassignTag(namespace, name, tag, newDigest string) error

ReassignTag reassigns a tag to a different function version.

func (*Engine) Start

func (e *Engine) Start() error

func (*Engine) StopFunction

func (e *Engine) StopFunction(namespace, name string) error

StopFunction stops a function and marks it as explicitly stopped to prevent auto-reload.

func (*Engine) UnloadFunction

func (e *Engine) UnloadFunction(namespace, name string) error

UnloadFunction unloads a function, removing it from memory but preserving its configuration.

func (*Engine) WasPreviouslyLoaded

func (e *Engine) WasPreviouslyLoaded(namespace, name string) (bool, map[string]string)

WasPreviouslyLoaded checks if a function was previously loaded and returns its config.

type ExecutionStats added in v0.1.1

type ExecutionStats struct {
	LastExecution        time.Time
	TotalExecutions      int64
	SuccessfulExecutions int64
	FailedExecutions     int64
}

ExecutionStats contains statistics about function execution

type ExtendedBuildRequest

type ExtendedBuildRequest struct {
	types.BuildRequest
	Manifest manifest.FunctionManifest `json:"manifest"`
}

type FunctionExecutor

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

func NewFunctionExecutor

func NewFunctionExecutor(pluginManager PluginManager, circuitBreakers CircuitBreakerManager,
	logStore *logging.FunctionLogStore, logger logging.Logger, defaultTimeout time.Duration) *FunctionExecutor

func (*FunctionExecutor) CallFunction

func (e *FunctionExecutor) CallFunction(ctx context.Context, namespace, name, entrypoint string, payload []byte) ([]byte, error)

func (*FunctionExecutor) DefaultTimeout

func (e *FunctionExecutor) DefaultTimeout() time.Duration

func (*FunctionExecutor) GetCircuitBreaker added in v0.1.1

func (e *FunctionExecutor) GetCircuitBreaker(namespace, name string) CircuitBreaker

func (*FunctionExecutor) GetStats added in v0.1.1

func (e *FunctionExecutor) GetStats(_, _ string) ExecutionStats

type FunctionLoader

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

func NewFunctionLoader

func NewFunctionLoader(registry registry.Registry, pluginManager PluginManager,
	circuitBreakers CircuitBreakerManager, logStore *logging.FunctionLogStore,
	logger logging.Logger) *FunctionLoader

func (*FunctionLoader) GetDigest added in v0.1.1

func (l *FunctionLoader) GetDigest(namespace, name string) (string, bool)

GetDigest returns the current digest of a function

func (*FunctionLoader) IsLoaded

func (l *FunctionLoader) IsLoaded(namespace, name string) bool

IsLoaded checks if a function is loaded.

func (*FunctionLoader) IsStopped

func (l *FunctionLoader) IsStopped(namespace, name string) bool

IsStopped checks if a function is stopped.

func (*FunctionLoader) LoadFunction

func (l *FunctionLoader) LoadFunction(ctx context.Context, namespace, name, identifier string, config map[string]string) error

LoadFunction loads a function with the specified identifier and configuration. This is a convenience method that calls LoadFunctionWithForce with force=false.

func (*FunctionLoader) LoadFunctionWithForce

func (l *FunctionLoader) LoadFunctionWithForce(ctx context.Context, namespace, name, identifier string, config map[string]string, force bool) error

LoadFunctionWithForce loads a function with the specified identifier and configuration, with the option to force loading even if the function is marked as stopped.

func (*FunctionLoader) StopFunction

func (l *FunctionLoader) StopFunction(namespace, name string) error

StopFunction stops a function and marks it as explicitly stopped, which prevents it from being automatically reloaded. It can only be reloaded with the force option.

Parameters:

  • namespace: The function namespace
  • name: The function name

Returns:

  • error: Any error that occurred during stopping

func (*FunctionLoader) UnloadFunction

func (l *FunctionLoader) UnloadFunction(namespace, name string) error

UnloadFunction unloads a function, removing it from memory but preserving its configuration for potential future reloading.

Parameters:

  • namespace: The function namespace
  • name: The function name

Returns:

  • error: Any error that occurred during unloading

func (*FunctionLoader) WasPreviouslyLoaded

func (l *FunctionLoader) WasPreviouslyLoaded(namespace, name string) (bool, map[string]string)

WasPreviouslyLoaded checks if a function was previously loaded.

type FunctionManager

type FunctionManager interface {
	RuntimeOperations
	BuildOperations
	StateOperations
}

type FunctionManagerImpl added in v0.1.1

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

func NewFunctionManager

func NewFunctionManager(loader *FunctionLoader, executor *FunctionExecutor, registry registry.Registry,
	functionSvc services.FunctionService, defaultTimeout time.Duration) *FunctionManagerImpl

func (*FunctionManagerImpl) BuildFunction added in v0.1.1

func (m *FunctionManagerImpl) BuildFunction(namespace, name, path, tag string, config manifest.FunctionManifest) (*types.BuildResult, error)

BuildFunction builds a function and stores it in the registry

func (*FunctionManagerImpl) CallFunction added in v0.1.1

func (m *FunctionManagerImpl) CallFunction(ctx context.Context, namespace, name, entrypoint string, payload []byte) ([]byte, error)

func (*FunctionManagerImpl) GetFunctionState added in v0.1.1

func (m *FunctionManagerImpl) GetFunctionState(namespace, name string) FunctionState

GetFunctionState returns the complete state information for a function

func (*FunctionManagerImpl) LoadFunction added in v0.1.1

func (m *FunctionManagerImpl) LoadFunction(ctx context.Context, namespace, name, identifier string, config map[string]string, force bool) error

LoadFunction loads a function with the specified identifier and configuration. If force is true, it will load even if the function is marked as stopped.

func (*FunctionManagerImpl) ReassignTag added in v0.1.1

func (m *FunctionManagerImpl) ReassignTag(namespace, name, tag, newDigest string) error

ReassignTag reassigns a tag to a different function version

func (*FunctionManagerImpl) StopFunction added in v0.1.1

func (m *FunctionManagerImpl) StopFunction(namespace, name string) error

func (*FunctionManagerImpl) UnloadFunction added in v0.1.1

func (m *FunctionManagerImpl) UnloadFunction(namespace, name string) error

type FunctionState

type FunctionState struct {
	// Basic state
	Loaded           bool // Whether the function is currently loaded
	Running          bool // Whether the function is currently running
	Stopped          bool // Whether the function has been explicitly stopped
	PreviouslyLoaded bool // Whether the function was previously loaded in this session

	// Configuration
	Config map[string]string // Current function configuration

	// Execution stats
	LastExecutionTime    time.Time // When the function was last executed
	TotalExecutions      int64     // Total number of executions
	SuccessfulExecutions int64     // Number of successful executions
	FailedExecutions     int64     // Number of failed executions

	// Circuit breaker status
	CircuitBreakerOpen bool // Whether the circuit breaker is open

	// Registry info
	Digest string   // Current function digest
	Tags   []string // Tags associated with this function
}

FunctionState contains the complete state information for a function.

type HandlerFunc

type HandlerFunc func(http.ResponseWriter, *http.Request) error

type Handlers

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

func NewHandlers

func NewHandlers(engine *Engine, logger logging.Logger) *Handlers

func (*Handlers) HTTPHandler

func (h *Handlers) HTTPHandler() http.Handler

func (*Handlers) UnixSocketHandler

func (h *Handlers) UnixSocketHandler() http.Handler

type Middleware

type Middleware func(HandlerFunc) HandlerFunc

type Options

type Options struct {
	// Default timeout for function operations
	DefaultTimeout time.Duration

	// Capacity of the log store
	LogStoreCapacity int

	CircuitBreakerSettings components.CircuitBreakerSettings
	PluginManagerSettings  components.PluginManagerSettings
}

func DefaultEngineOptions

func DefaultEngineOptions() *Options

func OptionsFromConfig

func OptionsFromConfig(cfg *config.Config) *Options

func (*Options) WithCircuitBreakerSettings

func (o *Options) WithCircuitBreakerSettings(settings components.CircuitBreakerSettings) *Options

func (*Options) WithDefaultTimeout

func (o *Options) WithDefaultTimeout(timeout time.Duration) *Options

func (*Options) WithLogStoreCapacity

func (o *Options) WithLogStoreCapacity(capacity int) *Options

func (*Options) WithPluginManagerSettings

func (o *Options) WithPluginManagerSettings(settings components.PluginManagerSettings) *Options

type PluginManager

type PluginManager = components.PluginManager

type PluginManagerSettings

type PluginManagerSettings = components.PluginManagerSettings

type RequestError

type RequestError struct {
	Message    string
	StatusCode int
	// contains filtered or unexported fields
}

func DomainErrorToRequestError added in v0.1.1

func DomainErrorToRequestError(err *domainerrors.DomainError) RequestError

func NewRequestError

func NewRequestError(message string, statusCode int) RequestError

func NewRequestErrorWithCause added in v0.1.1

func NewRequestErrorWithCause(message string, statusCode int, cause error) RequestError

func (RequestError) Error

func (e RequestError) Error() string

func (RequestError) Unwrap

func (e RequestError) Unwrap() error

type RuntimeOperations added in v0.1.1

type RuntimeOperations interface {
	// LoadFunction loads a function with the specified identifier and configuration.
	// If force is true, it will load even if the function is marked as stopped.
	LoadFunction(ctx context.Context, namespace, name, identifier string, config map[string]string, force bool) error

	// CallFunction calls a function with the specified parameters.
	CallFunction(ctx context.Context, namespace, name, entrypoint string, payload []byte) ([]byte, error)

	// UnloadFunction unloads a function, removing it from memory.
	UnloadFunction(namespace, name string) error

	// StopFunction stops a function and marks it as stopped so it won't be auto-loaded.
	StopFunction(namespace, name string) error
}

type Server

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

func NewServer

func NewServer(socketPath, httpAddr string, handlers *Handlers, logger logging.Logger) *Server

func (*Server) Start

func (s *Server) Start() error

type StateOperations added in v0.1.1

type StateOperations interface {
	// GetFunctionState returns the current state of a function.
	GetFunctionState(namespace, name string) FunctionState
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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