Documentation
¶
Index ¶
- Constants
- Variables
- func NewEntrypointError(entrypoint string) bacerrors.Error
- func NewFilesystemError(path string, err error) bacerrors.Error
- func NewInputConfigError(msg string) bacerrors.Error
- func NewLogError(err error) bacerrors.Error
- func NewMemoryLimitError(requested, max uint64) bacerrors.Error
- func NewModuleCompileError(path string, err error) bacerrors.Error
- func NewModuleLoadError(path string, err error) bacerrors.Error
- func NewModuleNotFoundError(path string) bacerrors.Error
- func NewOutputError(msg string) bacerrors.Error
- func NewSpecError(err error) bacerrors.Error
- func NewUnknownModuleError(moduleName string) bacerrors.Error
- func NewWASIError(err error) bacerrors.Error
- type Executor
- func (e *Executor) Cancel(ctx context.Context, executionID string) error
- func (e *Executor) GetLogStream(ctx context.Context, request messages.ExecutionLogsRequest) (io.ReadCloser, error)
- func (e *Executor) IsInstalled(context.Context) (bool, error)
- func (e *Executor) Run(ctx context.Context, request *executor.RunCommandRequest) (*models.RunCommandResult, error)
- func (*Executor) ShouldBid(ctx context.Context, request bidstrategy.BidStrategyRequest) (bidstrategy.BidStrategyResponse, error)
- func (*Executor) ShouldBidBasedOnUsage(ctx context.Context, request bidstrategy.BidStrategyRequest, ...) (bidstrategy.BidStrategyResponse, error)
- func (e *Executor) Start(ctx context.Context, request *executor.RunCommandRequest) error
- func (e *Executor) Wait(ctx context.Context, executionID string) (<-chan *models.RunCommandResult, <-chan error)
- type ModuleLoader
Constants ¶
const ( // WasmArch represents the WebAssembly architecture (32-bit) WasmArch = 32 // WasmPageSize represents the size of a WebAssembly memory page (64KB) WasmPageSize = 65536 // WasmMaxPagesLimit represents the maximum number of memory pages allowed (4GB) WasmMaxPagesLimit = 1 << (WasmArch / 2) // BytesInGB represents the number of bytes in a gigabyte BytesInGB = 1 << 30 )
WASM architecture and memory constants WebAssembly1: linear memory objects have sizes measured in pages. Each page is 65536 (2^16) bytes. In WebAssembly version 1, a linear memory can have at most 65536 pages, for a total of 2^32 bytes (4 gibibytes).
const ( ModuleNotFound = "ModuleNotFound" ModuleCompileError = "ModuleCompileError" ModuleLoadError = "ModuleLoadError" WASIError = "WASIError" UnknownModuleError = "UnknownModuleError" // Handler and Executor specific error codes SpecError = "SpecError" LogError = "LogError" EntrypointError = "EntrypointError" MemoryLimitError = "MemoryLimitError" FilesystemError = "FilesystemError" // Configuration error codes InputConfigError = "InputConfigError" OutputConfigError = "OutputConfigError" )
WASM-specific error codes
const Component = "WASM"
Variables ¶
var (
ActiveExecutions = lo.Must(telemetry.NewGauge(
wasmExecutorMeter,
"wasm_active_executions",
"Number of active WASM executions",
))
)
Functions ¶
func NewEntrypointError ¶ added in v1.7.0
NewEntrypointError creates an error when there's an issue with the entrypoint
func NewFilesystemError ¶ added in v1.7.0
NewFilesystemError creates an error when there's an issue with the filesystem
func NewInputConfigError ¶ added in v1.7.0
NewInputConfigError creates an error when there's an issue with input configuration
func NewLogError ¶ added in v1.7.0
NewLogError creates an error when there's an issue with logging
func NewMemoryLimitError ¶ added in v1.7.0
NewMemoryLimitError creates an error when memory limits are exceeded
func NewModuleCompileError ¶ added in v1.7.0
NewModuleCompileError creates an error when a WASM module fails to compile.
func NewModuleLoadError ¶ added in v1.7.0
NewModuleLoadError creates an error when a WASM module fails to load.
func NewModuleNotFoundError ¶ added in v1.7.0
NewModuleNotFoundError creates an error when a WASM module cannot be found in the filesystem.
func NewOutputError ¶ added in v1.7.0
NewOutputError creates an error when there's an issue with output configuration
func NewSpecError ¶ added in v1.7.0
NewSpecError creates an error when there's an issue with the WASM spec
func NewUnknownModuleError ¶ added in v1.7.0
NewUnknownModuleError creates an error when a module name cannot be resolved.
func NewWASIError ¶ added in v1.7.0
NewWASIError creates an error when there's an issue with the WASI module.
Types ¶
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor handles the execution of WebAssembly modules. It manages the lifecycle of WASM executions, including starting, waiting for completion, and handling cancellation.
func NewExecutor ¶
NewExecutor creates a new WASM executor instance.
func (*Executor) Cancel ¶ added in v1.0.4
Cancel tries to cancel a specific execution by its executionID. It returns an error if the execution is not found.
func (*Executor) GetLogStream ¶ added in v1.2.2
func (e *Executor) GetLogStream(ctx context.Context, request messages.ExecutionLogsRequest) (io.ReadCloser, error)
GetLogStream provides a stream of output logs for a specific execution. Parameters 'withHistory' and 'follow' control whether to include past logs and whether to keep the stream open for new logs, respectively. It returns an error if the execution is not found.
func (*Executor) IsInstalled ¶
IsInstalled checks if the WASM executor is available. Since WASM executor runs natively in Go, it's always available.
func (*Executor) Run ¶ added in v0.3.24
func (e *Executor) Run( ctx context.Context, request *executor.RunCommandRequest, ) (*models.RunCommandResult, error)
Run initiates and waits for the completion of an execution in one call. This method serves as a higher-level convenience function that internally calls Start and Wait methods. It returns the result of the execution or an error if either starting or waiting fails, or if the context is canceled.
func (*Executor) ShouldBid ¶ added in v1.0.4
func (*Executor) ShouldBid(ctx context.Context, request bidstrategy.BidStrategyRequest) (bidstrategy.BidStrategyResponse, error)
ShouldBid determines if the executor should bid on a job. WASM jobs don't have additional requirements, so it always returns true.
func (*Executor) ShouldBidBasedOnUsage ¶ added in v1.0.4
func (*Executor) ShouldBidBasedOnUsage( ctx context.Context, request bidstrategy.BidStrategyRequest, usage models.Resources, ) (bidstrategy.BidStrategyResponse, error)
ShouldBidBasedOnUsage determines if the executor should bid on a job based on resource usage. WASM jobs don't have additional requirements, so it always returns true.
func (*Executor) Start ¶ added in v1.0.4
Start initiates an execution based on the provided RunCommandRequest. It sets up the WASM runtime with appropriate memory limits and filesystem mounts, then starts the execution in a separate goroutine.
func (*Executor) Wait ¶ added in v1.0.4
func (e *Executor) Wait(ctx context.Context, executionID string) (<-chan *models.RunCommandResult, <-chan error)
Wait initiates a wait for the completion of a specific execution using its executionID. The function returns two channels: one for the result and another for any potential error. If the executionID is not found, an error is immediately sent to the error channel. Otherwise, an internal goroutine (doWait) is spawned to handle the asynchronous waiting. Callers should use the two returned channels to wait for the result of the execution or an error. This can be due to issues either beginning the wait or in getting the response. This approach allows the caller to synchronize Wait with calls to Start, waiting for the execution to complete.
type ModuleLoader ¶ added in v0.3.26
type ModuleLoader struct {
// contains filtered or unexported fields
}
ModuleLoader handles the loading and instantiation of WebAssembly modules. It manages module dependencies and ensures proper initialization order.
The loader supports: - Loading modules from the mounted filesystem - Dynamic resolution of imported modules at runtime - Automatic handling of WASI modules - Thread-safe module instantiation
Dynamic Loading: When a WASM module imports another module by name, the loader will: 1. Check if the module is already instantiated 2. If not, check if it's the WASI module 3. If not, look for a matching .wasm file in the mounted filesystem 4. If found, load and instantiate the module recursively 5. If not found, return an error
Module Resolution: - Direct paths: Load the WASM file at the given path - Directories: Look for a single .wasm file in the directory - Module names: Resolve against the mounted filesystem
func NewModuleLoader ¶ added in v0.3.26
func NewModuleLoader(runtime wazero.Runtime, config wazero.ModuleConfig, fs fs.FS) *ModuleLoader
NewModuleLoader creates a new module loader with the given runtime, configuration, and mounted filesystem.
func (*ModuleLoader) InstantiateModule ¶ added in v1.7.0
func (loader *ModuleLoader) InstantiateModule(ctx context.Context, modulePath string) (api.Module, error)
InstantiateModule loads and instantiates the module at the given path and all of its dependencies. It looks in the provided filesystem for modules.
This function calls itself recursively for any discovered dependencies on the loaded modules, so that the returned module has all of its dependencies fully instantiated and is ready to use.