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 ¶
- type JSONStore
- func (s *JSONStore) Delete(ctx context.Context, workflowID string) error
- func (s *JSONStore) List(ctx context.Context) ([]string, error)
- func (s *JSONStore) Load(ctx context.Context, workflowID string) (*workflow.ExecutionContext, error)
- func (s *JSONStore) Save(ctx context.Context, state *workflow.ExecutionContext) error
- type SQLiteHistoryStore
- func (s *SQLiteHistoryStore) Cleanup(ctx context.Context, olderThan time.Duration) (int, error)
- func (s *SQLiteHistoryStore) Close() error
- func (s *SQLiteHistoryStore) GetStats(ctx context.Context, filter *workflow.HistoryFilter) (*workflow.HistoryStats, error)
- func (s *SQLiteHistoryStore) List(ctx context.Context, filter *workflow.HistoryFilter) ([]*workflow.ExecutionRecord, error)
- func (s *SQLiteHistoryStore) Record(ctx context.Context, record *workflow.ExecutionRecord) error
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 ¶
NewJSONStore creates a new JSON store.
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 ¶
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 ¶
func (s *SQLiteHistoryStore) GetStats(ctx context.Context, filter *workflow.HistoryFilter) (*workflow.HistoryStats, error)
GetStats returns aggregated statistics for executions matching the filter.
func (*SQLiteHistoryStore) List ¶
func (s *SQLiteHistoryStore) List(ctx context.Context, filter *workflow.HistoryFilter) ([]*workflow.ExecutionRecord, error)
List retrieves execution records matching the filter criteria.
func (*SQLiteHistoryStore) Record ¶
func (s *SQLiteHistoryStore) Record(ctx context.Context, record *workflow.ExecutionRecord) error
Record stores a workflow execution record.