Documentation
¶
Index ¶
- Constants
- Variables
- func CloneAny(value any) any
- func CloneAnyMap(in map[string]any) map[string]any
- func CloneContext(in map[string]map[string]any) map[string]map[string]any
- func CloneFacts(in map[string]FactValue) map[string]FactValue
- type Activity
- type ActivityID
- type ActivityRegistry
- type ActivityTask
- type AtomID
- type Clock
- type DiagnosticError
- type Dirty
- type DurabilityProvider
- type DurableStateError
- type Engine
- func (e *Engine) EnableStrictFastRuntime() error
- func (e *Engine) Execution(id string) *Run
- func (e *Engine) Module() *compiler.Module
- func (e *Engine) Patch(ctx context.Context, executionID string, patch map[string]any) error
- func (e *Engine) Query(ctx context.Context, executionID string, queryName string) (map[string]any, error)
- func (e *Engine) Replay(ctx context.Context, executionID string) (*Execution, error)
- func (e *Engine) RunUntilIdle(ctx context.Context, executionID string) error
- func (e *Engine) SetClock(clock Clock)
- func (e *Engine) SetTraceLevel(level TraceLevel)
- func (e *Engine) Signal(ctx context.Context, executionID string, signalName string, ...) error
- func (e *Engine) Start(ctx context.Context, executionID string, initialContext map[string]any) error
- func (e *Engine) StartWorker(ctx context.Context, opts WorkerOptions) error
- type EventNamer
- type Execution
- type ExecutionState
- type Explanation
- type FactValue
- type FieldID
- type HistoryEntry
- type RetryScheduledError
- type RuleID
- type RuleQueue
- type Run
- func (r *Run) Cancel(ctx context.Context) error
- func (r *Run) Dispatch(ctx context.Context, event any) error
- func (r *Run) Explain(ctx context.Context) (*Explanation, error)
- func (r *Run) History(ctx context.Context) ([]HistoryEntry, error)
- func (r *Run) ID() string
- func (r *Run) Patch(ctx context.Context, patch map[string]any) error
- func (r *Run) PendingActivities(ctx context.Context) ([]ActivityTask, error)
- func (r *Run) Signal(ctx context.Context, name string, payload map[string]any) error
- func (r *Run) State(ctx context.Context, target any) error
- func (r *Run) Status(ctx context.Context) (Status, error)
- type SignalID
- type Status
- type Store
- type StoreDurability
- type StoreTransaction
- type TaskDedupStore
- type TaskStatus
- type TraceLevel
- type TransactionalStore
- type Value
- type ValueKind
- type WorkerOptions
Constants ¶
const MaxFastClauses = 1024
Variables ¶
var ErrExecutionNotFound = errors.New("execution not found")
var ErrRetryScheduled = errors.New("activity retry scheduled")
ErrRetryScheduled indicates that the current activity attempt failed, but the task was durably returned to pending state and may be retried later.
Functions ¶
func CloneAny ¶
CloneAny returns an isolated copy of maps, slices and arrays, including named and typed collections stored behind interface values. Pointer values are intentionally treated as opaque application objects.
func CloneAnyMap ¶
CloneAnyMap returns a deep copy of a map[string]any.
func CloneContext ¶
CloneContext returns a deep copy of a context map (ContextName -> FieldName -> Value).
Types ¶
type ActivityID ¶
type ActivityID = compiler.ActivityID
type ActivityRegistry ¶
type ActivityTask ¶
type ActivityTask struct {
ID string
ExecutionID string
RuleName string
ActivityName string
Input map[string]any
IdempotencyKey string
Status TaskStatus
Attempt int
MaxAttempts int
LockedBy string
LockedUntil time.Time
NextAttemptAt time.Time
Result map[string]any
Error string
CreatedAt time.Time
UpdatedAt time.Time
}
type DiagnosticError ¶
type DurabilityProvider ¶
type DurabilityProvider interface {
Durability() StoreDurability
}
DurabilityProvider lets a Store declare its persistence semantics without conflating them with transaction support. Production validation uses this capability in addition to TransactionalStore.
type DurableStateError ¶
DurableStateError is implemented by domain or flow-control errors whose state changes have been staged in the transaction and must be committed to the store even though an error is returned to the caller.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func NewEngine ¶
func NewEngine(module *compiler.Module, store Store, activities ActivityRegistry) *Engine
func (*Engine) EnableStrictFastRuntime ¶
func (*Engine) Execution ¶
Execution returns a handle that can dispatch typed events and read state.
func (*Engine) RunUntilIdle ¶
func (*Engine) SetTraceLevel ¶
func (e *Engine) SetTraceLevel(level TraceLevel)
func (*Engine) StartWorker ¶
func (e *Engine) StartWorker(ctx context.Context, opts WorkerOptions) error
type EventNamer ¶
type EventNamer interface {
AxiomEventName() string
}
EventNamer overrides the signal name derived from a Go event type.
type Execution ¶
type Execution struct {
ID string
Domain string
Status Status
Context map[string]map[string]any
Computed map[string]any
Facts map[string]FactValue
RuntimeState ExecutionState
ModuleHash string
CompilerVersion string
PlanVersion string
Version int
CreatedAt time.Time
UpdatedAt time.Time
}
func CloneExecution ¶
CloneExecution returns a deep copy of an Execution.
func ReplayFromHistory ¶
func ReplayFromHistory(module *compiler.Module, history []HistoryEntry) (*Execution, error)
type ExecutionState ¶
type Explanation ¶
type Explanation struct {
Status Status
Facts map[string]FactValue
PendingActivities []*ActivityTask
History []HistoryEntry
}
Explanation is the typed form of the built-in explain query.
type HistoryEntry ¶
type RetryScheduledError ¶
type RetryScheduledError struct {
TaskID string
ExecutionID string
ActivityName string
Attempt int
MaxAttempts int
NextAttemptAt time.Time
}
RetryScheduledError describes a persisted retry checkpoint. Low-level users of Engine.RunUntilIdle can inspect this error; the higher-level Run API waits for the next attempt automatically.
func (*RetryScheduledError) Error ¶
func (e *RetryScheduledError) Error() string
func (*RetryScheduledError) ShouldCommitState ¶
func (e *RetryScheduledError) ShouldCommitState() bool
func (*RetryScheduledError) Unwrap ¶
func (e *RetryScheduledError) Unwrap() error
type Run ¶
type Run struct {
// contains filtered or unexported fields
}
Run is an ergonomic handle for one execution.
func (*Run) Dispatch ¶
Dispatch creates the execution when needed, sends an event and drains inline activities, including durable retries, until the execution is idle.
func (*Run) Patch ¶
Patch applies field changes to the execution context and drains inline work, including durable retries.
func (*Run) PendingActivities ¶
func (r *Run) PendingActivities(ctx context.Context) ([]ActivityTask, error)
func (*Run) Signal ¶
Signal dispatches an explicitly named signal and drains inline work, including any durable retries due before the caller's context ends.
type Store ¶
type Store interface {
CreateExecution(ctx context.Context, execution *Execution) error
GetExecution(ctx context.Context, id string) (*Execution, error)
SaveExecution(ctx context.Context, execution *Execution) error
AppendHistory(ctx context.Context, executionID string, entryType string, payload map[string]any) error
ListHistory(ctx context.Context, executionID string) ([]HistoryEntry, error)
EnqueueTask(ctx context.Context, task *ActivityTask) error
ListTasks(ctx context.Context, executionID string) ([]*ActivityTask, error)
PollTask(ctx context.Context, executionID string) (*ActivityTask, error)
PollTaskWithLease(ctx context.Context, executionID string, workerID string, leaseTTL time.Duration) (*ActivityTask, error)
HeartbeatTask(ctx context.Context, taskID string, workerID string) error
RecoverExpiredLeases(ctx context.Context, executionID string, leaseTTL time.Duration) (int, error)
CompleteTask(ctx context.Context, taskID string, result map[string]any) error
FailTask(ctx context.Context, taskID string, errorMessage string) error
UpdateTask(ctx context.Context, task *ActivityTask) error
}
type StoreDurability ¶
type StoreDurability string
StoreDurability describes how strongly a Store persists committed writes. The level is deliberately independent from transaction support: atomicity and durability are separate capabilities.
const ( // StoreDurabilityEphemeral means state is process-local and is lost when the // process exits or crashes. StoreDurabilityEphemeral StoreDurability = "ephemeral" // StoreDurabilityBestEffort means writes reach a persistent backend but are // not synchronously forced to stable storage. Recent commits may be lost on // host or power failure with no configured upper bound. StoreDurabilityBestEffort StoreDurability = "best-effort" // StoreDurabilityBuffered means persistence is asynchronous with a bounded // application-configured flush interval. A crash may lose the most recent // buffered window. StoreDurabilityBuffered StoreDurability = "buffered" // StoreDurabilitySynchronous means a successful commit is synchronously // persisted by the backend before it is reported as complete. StoreDurabilitySynchronous StoreDurability = "synchronous" )
type StoreTransaction ¶
type TaskDedupStore ¶
type TaskStatus ¶
type TaskStatus string
const ( TaskPending TaskStatus = "pending" TaskRunning TaskStatus = "running" TaskCompleted TaskStatus = "completed" TaskFailed TaskStatus = "failed" TaskSuperseded TaskStatus = "superseded" )
type TraceLevel ¶
type TraceLevel string
const ( TraceAggregate TraceLevel = "aggregate" TraceFull TraceLevel = "full" TraceMinimal TraceLevel = "minimal" )
type TransactionalStore ¶
type TransactionalStore interface {
BeginTransaction(ctx context.Context) (StoreTransaction, error)
}