dagstate

package
v2.11.2 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package dagstate defines persistent state shared across DAG runs.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound      = errors.New("dag state: not found")
	ErrConflict      = errors.New("dag state: conflict")
	ErrInvalidRef    = errors.New("dag state: invalid ref")
	ErrInvalidValue  = errors.New("dag state: invalid value")
	ErrValueTooLarge = errors.New("dag state: value too large")
)

Functions

func HashValue

func HashValue(value json.RawMessage) string

HashValue returns the SHA-256 hash of a normalized state value.

func NormalizeValue

func NormalizeValue(data []byte) (json.RawMessage, error)

NormalizeValue validates and compacts a JSON value before storage.

func ValidateKeyPrefix

func ValidateKeyPrefix(prefix string) error

ValidateKeyPrefix rejects malformed key prefixes for list filters.

Types

type Entry

type Entry struct {
	Ref
	Value     json.RawMessage `json:"value"`
	Version   int64           `json:"version"`
	Hash      string          `json:"hash"`
	CreatedAt time.Time       `json:"created_at"`
	UpdatedAt time.Time       `json:"updated_at"`
	UpdatedBy *UpdateSource   `json:"updated_by,omitempty"`
}

Entry is a versioned JSON value stored for a state reference.

func (*Entry) Clone

func (e *Entry) Clone() *Entry

Clone returns a deep copy of the entry.

type ListOptions

type ListOptions struct {
	Scope     Scope
	Namespace string
	KeyPrefix string
	Limit     int
}

ListOptions filters state entries by scope, namespace, and key prefix.

func (ListOptions) RecordIDPrefix

func (o ListOptions) RecordIDPrefix() (string, error)

RecordIDPrefix returns the storage prefix for a list filter.

func (ListOptions) Validate

func (o ListOptions) Validate() error

Validate rejects malformed list filters before store access.

type PutOptions

type PutOptions struct {
	ExpectedVersion *int64
	CreateOnly      bool
	UpdatedBy       *UpdateSource
}

PutOptions controls optimistic concurrency and audit metadata for writes.

type Ref

type Ref struct {
	Scope     Scope  `json:"scope"`
	Namespace string `json:"namespace"`
	Key       string `json:"key"`
}

Ref identifies one persistent DAG state entry.

func RefFromRecordID

func RefFromRecordID(id string) (Ref, error)

RefFromRecordID parses a storage key back into a state reference.

func (Ref) RecordID

func (r Ref) RecordID() (string, error)

RecordID returns the stable storage key for the reference.

func (Ref) Validate

func (r Ref) Validate() error

Validate rejects malformed state references.

type Scope

type Scope string

Scope identifies the namespace strategy for a state entry.

const (

	// ScopeDAG stores state under the current DAG name.
	ScopeDAG Scope = "dag"
	// ScopeRootDAG stores state under the root DAG name for nested runs.
	ScopeRootDAG Scope = "root_dag"
	// ScopeGlobal stores state in a process-wide namespace.
	ScopeGlobal Scope = "global"
	// ScopeCustom stores state in an explicitly provided namespace.
	ScopeCustom Scope = "custom"

	// DefaultGlobalNamespace is used when global state does not need a user namespace.
	DefaultGlobalNamespace = "_"
	// DefaultMaxValueBytes is the maximum normalized JSON payload size for one state entry.
	DefaultMaxValueBytes = 1 << 20
)

func (Scope) Valid

func (s Scope) Valid() bool

Valid reports whether the scope is supported.

type Store

type Store interface {
	Get(ctx context.Context, ref Ref) (*Entry, error)
	Put(ctx context.Context, ref Ref, value json.RawMessage, opts PutOptions) (*Entry, error)
	Delete(ctx context.Context, ref Ref) (bool, error)
	List(ctx context.Context, opts ListOptions) ([]*Entry, error)
}

Store persists JSON state entries across DAG runs.

type UpdateSource

type UpdateSource struct {
	DAGName   string `json:"dag_name,omitempty"`
	DAGRunID  string `json:"dag_run_id,omitempty"`
	AttemptID string `json:"attempt_id,omitempty"`
	StepName  string `json:"step_name,omitempty"`
}

UpdateSource records the DAG run and step that last updated an entry.

func (*UpdateSource) Clone

func (u *UpdateSource) Clone() *UpdateSource

Clone returns a copy of the update source.

Jump to

Keyboard shortcuts

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