sessionledger

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package sessionledger supplies a shared in-memory ledger for runtime and application tests. No production composition root uses this fixture.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct {
	Mu   sync.Mutex
	Runs map[string]*ledger.Run
	// bySession preserves insertion order so ActiveRun is deterministic.
	Order []string
	Token int64

	AdmitErr    error
	ClaimErr    error
	TokenErr    error
	PrepareErr  error
	FinalizeErr error
	ClaimHook   func(runID string)

	Admits    int
	Claims    int
	Finalized []ledger.FinalizeParams
}

Store is an in-memory ledger with the same guarantees the PostgreSQL adapter provides: one active run per session, fenced idempotent transitions, and a monotonic token sequence. It exists so admission ordering can be tested without a database; the adapter's own SQL is covered by its integration test.

func New

func New() *Store

func (*Store) ActiveRun

func (f *Store) ActiveRun(_ context.Context, sessionID string) (ledger.Run, error)

func (*Store) Admit

func (f *Store) Admit(_ context.Context, params ledger.AdmitParams) (ledger.Run, bool, error)

func (*Store) Claim

func (f *Store) Claim(_ context.Context, params ledger.ClaimParams) (ledger.Run, bool, error)

func (*Store) Counts

func (f *Store) Counts() (admits, claims int)

func (*Store) ErrorCode

func (f *Store) ErrorCode(runID string) string

func (*Store) Finalize

func (f *Store) Finalize(_ context.Context, params ledger.FinalizeParams) (ledger.Run, bool, error)

func (*Store) Get

func (f *Store) Get(_ context.Context, runID string) (ledger.Run, error)

func (*Store) GetByInvocation

func (f *Store) GetByInvocation(_ context.Context, sessionID, invocationID string) (ledger.Run, error)

func (*Store) InsertClaimed

func (f *Store) InsertClaimed(runID, sessionID string, token int64, generation string)

insertClaimed records a run that some owner took and never finished, which is what the reaper finds after that owner disappears.

func (*Store) InsertOrphan

func (f *Store) InsertOrphan(runID, sessionID, invocationID, fingerprint string)

insertOrphan records an admission that committed under a process that died before it could claim anything.

func (*Store) LatestRun

func (f *Store) LatestRun(_ context.Context, sessionID string) (ledger.Run, error)

func (*Store) NextFencingToken

func (f *Store) NextFencingToken(context.Context) (int64, error)

func (*Store) OrphanedRuns

func (f *Store) OrphanedRuns(_ context.Context, query ledger.OrphanQuery) ([]ledger.Run, error)

func (*Store) PrepareFinish

func (f *Store) PrepareFinish(_ context.Context, params ledger.PrepareFinishParams) (ledger.Run, bool, error)

func (*Store) RequestAbort

func (f *Store) RequestAbort(_ context.Context, runID string) (ledger.Run, bool, error)

func (*Store) Resume

func (f *Store) Resume(_ context.Context, runID string, token int64) (ledger.Run, bool, error)

func (*Store) SetFinalizeErr

func (f *Store) SetFinalizeErr(err error)

func (*Store) SetPrepareErr

func (f *Store) SetPrepareErr(err error)

func (*Store) SetWaitingDecision

func (f *Store) SetWaitingDecision(_ context.Context, runID string, token int64) (ledger.Run, bool, error)

func (*Store) StaleGenerationRuns

func (f *Store) StaleGenerationRuns(_ context.Context, query ledger.StaleGenerationQuery) ([]ledger.Run, error)

StaleGenerationRuns mirrors the adapter's keyset sweep: active rows that were claimed by an incarnation other than the current one, ordered so a cursor can page through them.

func (*Store) State

func (f *Store) State(runID string) ledger.State

func (*Store) TerminalWrites

func (f *Store) TerminalWrites() []ledger.FinalizeParams

Jump to

Keyboard shortcuts

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