store

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: EUPL-1.2 Imports: 13 Imported by: 0

Documentation

Overview

Package store provides infrastructure adapters for state persistence and execution history.

This package implements StateStore and HistoryStore ports from the domain layer, providing durable storage for workflow state and execution records:

  • JSONStore: Atomic JSON file persistence for workflow execution state
  • SQLiteHistoryStore: SQLite-based execution history with WAL mode for concurrent access

Architecture:

  • Domain defines: StateStore and HistoryStore port interfaces
  • Infrastructure provides: JSONStore (state), SQLiteHistoryStore (history)
  • Application injects: Store implementations via dependency injection

JSONStore Example:

store := store.NewJSONStore(basePath)
err := store.Save(ctx, executionContext)
if err != nil {
    // Handle save error
}
// State persisted atomically to JSON file

SQLiteHistoryStore Example:

histStore, err := store.NewSQLiteHistoryStore(dbPath)
if err != nil {
    // Handle init error
}
defer histStore.Close()
err = histStore.Record(ctx, executionRecord)
// Execution history persisted to SQLite

State Persistence (JSONStore):

  • Atomic writes via temp file + rename pattern
  • File locking for concurrent access prevention
  • One JSON file per workflow execution (workflowID.json)
  • ExecutionContext serialization with full state tree

History Persistence (SQLiteHistoryStore):

  • SQLite WAL mode enables concurrent reads/writes
  • Execution records include: workflow ID, status, duration, timestamps
  • Query filtering by status, time range, workflow name
  • Statistics aggregation and cleanup for old records
  • Thread-safe with internal mutex protection

Component: C056 Infrastructure Package Documentation Layer: Infrastructure

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSONStore

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

JSONStore implements StateStore for JSON file persistence.

func NewJSONStore

func NewJSONStore(basePath string) *JSONStore

NewJSONStore creates a new JSON store.

func (*JSONStore) Delete

func (s *JSONStore) Delete(ctx context.Context, workflowID string) error

Delete removes a state file.

func (*JSONStore) List

func (s *JSONStore) List(ctx context.Context) ([]string, error)

List returns all stored workflow IDs.

func (*JSONStore) Load

func (s *JSONStore) Load(ctx context.Context, workflowID string) (*workflow.ExecutionContext, error)

Load retrieves execution state from a JSON file.

func (*JSONStore) Save

func (s *JSONStore) Save(ctx context.Context, state *workflow.ExecutionContext) error

Save persists execution state to a JSON file with atomic write. Uses unique temp file names to prevent concurrent write corruption.

type SQLiteHistoryStore

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

SQLiteHistoryStore implements HistoryStore using SQLite with WAL mode. This enables concurrent workflow executions without exclusive directory locks.

func NewSQLiteHistoryStore

func NewSQLiteHistoryStore(path string) (*SQLiteHistoryStore, error)

NewSQLiteHistoryStore creates a new SQLite-backed history store. The database file will be created at the specified path. WAL mode is enabled for concurrent read/write access.

func (*SQLiteHistoryStore) Cleanup

func (s *SQLiteHistoryStore) Cleanup(ctx context.Context, olderThan time.Duration) (int, error)

Cleanup removes execution records older than the specified duration. Returns the number of records deleted.

func (*SQLiteHistoryStore) Close

func (s *SQLiteHistoryStore) Close() error

Close gracefully shuts down the SQLite connection. Safe to call multiple times.

func (*SQLiteHistoryStore) GetStats

GetStats returns aggregated statistics for executions matching the filter.

func (*SQLiteHistoryStore) List

List retrieves execution records matching the filter criteria.

func (*SQLiteHistoryStore) Record

Record stores a workflow execution record.

Jump to

Keyboard shortcuts

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