executor

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package executor implements the imperative shell for executing plans. It provides transaction safety with two-phase commit and rollback capabilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checkpoint

type Checkpoint struct {
	ID        CheckpointID
	CreatedAt time.Time
	// contains filtered or unexported fields
}

Checkpoint records executed operations for rollback.

func (*Checkpoint) GetOperation

func (c *Checkpoint) GetOperation(id domain.OperationID) (domain.Operation, bool)

GetOperation retrieves an operation by ID with thread safety. Returns the operation and true if found, or nil and false if not found.

func (*Checkpoint) Len

func (c *Checkpoint) Len() int

Len returns the number of operations in the checkpoint.

func (*Checkpoint) ListOperations

func (c *Checkpoint) ListOperations() []domain.Operation

ListOperations returns a snapshot of all operations in the checkpoint. The returned slice is a copy and safe to use concurrently.

func (*Checkpoint) Lookup

Lookup retrieves an operation from the checkpoint. Returns nil if the operation is not found.

func (*Checkpoint) Record

func (c *Checkpoint) Record(id domain.OperationID, op domain.Operation)

Record stores an executed operation in the checkpoint.

type CheckpointID

type CheckpointID string

CheckpointID uniquely identifies a checkpoint.

type CheckpointStore

type CheckpointStore interface {
	Create(ctx context.Context) *Checkpoint
	Delete(ctx context.Context, id CheckpointID) error
	Restore(ctx context.Context, id CheckpointID) (*Checkpoint, error)
}

CheckpointStore manages checkpoint persistence.

type ExecutionResult

type ExecutionResult struct {
	Executed   []domain.OperationID
	Failed     []domain.OperationID
	RolledBack []domain.OperationID
	Errors     []error
}

ExecutionResult contains the outcome of plan execution.

func (ExecutionResult) PartialFailure

func (r ExecutionResult) PartialFailure() bool

PartialFailure returns true if some but not all operations succeeded.

func (ExecutionResult) Success

func (r ExecutionResult) Success() bool

Success returns true if all operations executed successfully.

type Executor

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

Executor executes validated plans with transaction safety.

func New

func New(opts Opts) *Executor

New creates a new Executor with the given options. If no checkpoint store is provided, a memory-based store is used. For metrics collection, wrap the returned executor with NewInstrumented().

func (*Executor) Execute

Execute executes a plan with two-phase commit and automatic rollback on failure.

type InstrumentedExecutor

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

InstrumentedExecutor wraps Executor with metrics collection.

func NewInstrumented

func NewInstrumented(inner *Executor, metrics domain.Metrics) *InstrumentedExecutor

NewInstrumented creates an executor with metrics instrumentation.

func (*InstrumentedExecutor) Execute

Execute executes a plan with metrics collection.

type MemoryCheckpointStore

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

MemoryCheckpointStore keeps checkpoints in memory. Suitable for testing and simple cases where persistence is not required.

func NewMemoryCheckpointStore

func NewMemoryCheckpointStore() *MemoryCheckpointStore

NewMemoryCheckpointStore creates a new in-memory checkpoint store.

func (*MemoryCheckpointStore) Create

func (*MemoryCheckpointStore) Delete

func (*MemoryCheckpointStore) Restore

type Opts

type Opts struct {
	FS         domain.FS
	Logger     domain.Logger
	Tracer     domain.Tracer
	Metrics    domain.Metrics
	Checkpoint CheckpointStore
}

Opts configures executor creation.

Jump to

Keyboard shortcuts

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