kernel

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 2 Imported by: 0

README

kernel (internal)

Import: github.com/kausys/azync/workflow/kernel

Pure in-memory workflow history engine: event log, command cursor, replay/park decisions. No SQL, no driver, no network.

Why it exists

Separates deterministic replay math from persistence and worker orchestration:

  • workflow loads history from WorkflowStore, runs handlers, schedules Operations/timers/signals.
  • kernel only answers: given this history + next command, replay or park?

That keeps the hard nondeterminism rules unit-testable without Postgres.

Who should import it

  • Prefer workflow for applications.
  • Import kernel only for tools, conformance helpers, or tests of the pure engine.

Parent package notes: ../README.md · User guide: ../../workflow.md.

Documentation

Overview

Package kernel is the pure in-memory history/command/replay engine for workflow-as-code. It has no I/O and no driver dependency: persistence and workers sit above it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	Type    CommandType
	Payload json.RawMessage
}

Command is emitted by the workflow function during replay when it reaches a point that needs a new durable effect.

type CommandType

type CommandType string

Command is a side-effect request produced by replay when history is exhausted for a given workflow decision point.

const (
	CommandScheduleOperation CommandType = "ScheduleOperation"
	CommandStartTimer        CommandType = "StartTimer"
	CommandCompleteWorkflow  CommandType = "CompleteWorkflow"
	CommandFailWorkflow      CommandType = "FailWorkflow"
	CommandSuspendWorkflow   CommandType = "SuspendWorkflow"
)

type Cursor

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

Cursor walks history during replay.

func NewCursor

func NewCursor(h *History) *Cursor

NewCursor starts at the beginning of h.

func (*Cursor) Expect

func (c *Cursor) Expect(typ EventType) (Event, error)

Expect consumes the next event and requires typ. On mismatch or exhaustion it returns a ReplayError (exhaustion means the caller should schedule a command instead — use TakeOrCommand).

func (*Cursor) Next

func (c *Cursor) Next() (Event, bool)

Next returns the next event, or false when the cursor has caught up (the workflow must then emit commands).

func (*Cursor) Peek

func (c *Cursor) Peek() (Event, bool)

Peek returns the next event without advancing.

func (*Cursor) TakeOrCommand

func (c *Cursor) TakeOrCommand(typ EventType) (Event, bool, error)

TakeOrCommand returns the next matching event, or ok=false when history is exhausted so the caller can emit a command.

type Event

type Event struct {
	Seq     int64
	Type    EventType
	Payload json.RawMessage
}

Event is one append-only history record.

type EventType

type EventType string

EventType classifies a history event.

const (
	EventWorkflowStarted   EventType = "WorkflowStarted"
	EventWorkflowCompleted EventType = "WorkflowCompleted"
	EventWorkflowFailed    EventType = "WorkflowFailed"
	EventWorkflowCancelled EventType = "WorkflowCancelled"
	EventWorkflowSuspended EventType = "WorkflowSuspended"

	EventOperationScheduled EventType = "OperationScheduled"
	EventOperationCompleted EventType = "OperationCompleted"
	EventOperationFailed    EventType = "OperationFailed"
	EventTimerStarted       EventType = "TimerStarted"
	EventTimerFired         EventType = "TimerFired"
	EventSignalReceived     EventType = "SignalReceived"
	EventMarkerRecorded     EventType = "MarkerRecorded"
)

type History

type History struct {
	Events []Event
}

History is an append-only ordered event log.

func (*History) Append

func (h *History) Append(typ EventType, payload json.RawMessage) Event

Append adds an event with the next sequence number.

func (*History) NextSeq

func (h *History) NextSeq() int64

NextSeq returns the next EventSeq to append.

type ReplayError

type ReplayError struct {
	Msg string
}

ReplayError is a non-deterministic or corrupt-history failure.

func (ReplayError) Error

func (e ReplayError) Error() string

Jump to

Keyboard shortcuts

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