instance

package
v0.0.0-...-4afd048 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrExecutionNotCancellable = errors.New("execution already reached a terminal state")

ErrExecutionNotCancellable reports that an execution cannot be cancelled because it has already reached a terminal state. It is deliberately distinct from ErrExecutionNotFound: the execution exists and a client can read its outcome, it simply cannot be stopped any more.

View Source
var ErrExecutionNotFound = errors.New("execution was not found")

ErrExecutionNotFound reports that no execution carries the requested ID on this instance.

Functions

This section is empty.

Types

type Instance

type Instance struct {
	ID        string
	Key       protocol.InstanceKey
	Blueprint *types.ExecutionBlueprint
	// contains filtered or unexported fields
}

func New

func New(
	parent context.Context,
	id string,
	key protocol.InstanceKey,
	assembly *shared.Assembly,
	workers int,
	persistentStore storage.Store,
	opts ...Option,
) (*Instance, error)

func (*Instance) Bus

func (i *Instance) Bus() *event.Bus

func (*Instance) CancelExecution

func (i *Instance) CancelExecution(ctx context.Context, executionID shared.ID, reason error) error

CancelExecution stops an execution at the caller's request.

Cancellation goes through the scheduler when one exists, because the scheduler owns execution scopes: it is the component that bound the scope when the execution started, so it is the one that can cancel it and record the decision. A restored instance has no scheduler -- and therefore no work to stop -- so there the execution's record is simply corrected and persisted.

func (*Instance) EventStore

func (i *Instance) EventStore() *event.Store

func (*Instance) Events

func (i *Instance) Events(ctx context.Context, eventID shared.ID, after shared.ID) (<-chan stream.Message, error)

Events composes persisted history with live bus events for the execution.

func (*Instance) Execute

func (i *Instance) Execute(ctx context.Context, input map[string]any) (*execution.Execution, error)

func (*Instance) GetExecution

func (i *Instance) GetExecution(id shared.ID) (*execution.Execution, bool)

func (*Instance) ListExecutionEvents

func (i *Instance) ListExecutionEvents(ctx context.Context, executionID shared.ID) ([]event.Event, error)

func (*Instance) ListExecutions

func (i *Instance) ListExecutions() []*execution.Execution

func (*Instance) Start

func (i *Instance) Start() error

func (*Instance) Status

func (i *Instance) Status() Status

func (*Instance) Stop

func (i *Instance) Stop() error

func (*Instance) Store

type Manager

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

func NewManager

func NewManager(parent context.Context, workers int, detachedDrainTimeout time.Duration, store storage.Store, assemblies *assembly.Repository) *Manager

func (*Manager) Clear

func (m *Manager) Clear(ctx context.Context) error

Clear stops and removes every tracked instance.

func (*Manager) Get

func (m *Manager) Get(key protocol.InstanceKey) (*Instance, bool)

func (*Manager) GetByID

func (m *Manager) GetByID(id string) (*Instance, bool)

func (*Manager) GetOrCreate

func (m *Manager) GetOrCreate(ctx context.Context, key protocol.InstanceKey) (*Instance, bool, error)

GetOrCreate returns the live runtime for key, lazily constructing it from the durable RegisteredAssembly when it is not already running. Registration itself never creates an instance; this is the only entry point that does. The key may be partial (assemblyID, assemblyID:latest, assemblyID:version); it is resolved to its canonical form first so every addressing style shares the same runtime.

func (*Manager) List

func (m *Manager) List(opts protocol.ListOptions) []*Instance

func (*Manager) Remove

func (m *Manager) Remove(ctx context.Context, target string) (removed bool, err error)

Remove stops and removes the instance addressed by target (an instance ID or a colon-encoded assembly key). The instance's executions and events are deleted along with its durable metadata.

func (*Manager) RemoveByAssembly

func (m *Manager) RemoveByAssembly(ctx context.Context, key protocol.InstanceKey) (int, error)

RemoveByAssembly stops and removes every instance whose key addresses the given assembly, optionally scoped to the key's version. Returns the number of instances removed.

func (*Manager) Resolve

func (m *Manager) Resolve(ctx context.Context, key protocol.InstanceKey) (*Instance, bool)

Resolve returns the live runtime for key without creating it. An exact key matches directly; a partial key (name, name:version, or one carrying a hash or env) is resolved through the registered assemblies so version-without-hash addresses the most recently registered artifact. Returns false when no instance exists for the key.

func (*Manager) Stop

func (m *Manager) Stop(id string) error

type Option

type Option func(*options)

Option configures an Instance at construction time.

func WithDetachedDrainTimeout

func WithDetachedDrainTimeout(timeout time.Duration) Option

WithDetachedDrainTimeout sets how long detached capability work may continue after the instance stops. Detached work outlives its caller by design, so draining it is bounded rather than unlimited; a non-positive duration selects the engine default.

func WithResolvedCapabilityRuntimes

func WithResolvedCapabilityRuntimes(resolved []capabilityrt.ResolvedCapabilityRuntime) Option

WithResolvedCapabilityRuntimes supplies the frozen capability runtime set persisted with the assembly's registration.

type Status

type Status string
const (
	StatusStarting Status = "starting"
	StatusRunning  Status = "running"
	StatusStopping Status = "stopping"
	StatusStopped  Status = "stopped"
	StatusFailed   Status = "failed"
)

Jump to

Keyboard shortcuts

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