Documentation
¶
Index ¶
- Constants
- Variables
- func IsAttemptDirName(name string) bool
- func ParseStatusFile(file string) (*ir.DAGRunStatus, error)
- type Attempt
- func (att *Attempt) Abort(ctx context.Context) error
- func (att *Attempt) Close(ctx context.Context) error
- func (att *Attempt) Compact(ctx context.Context) error
- func (att *Attempt) Exists() bool
- func (att *Attempt) Hidden() bool
- func (att *Attempt) Hide(ctx context.Context) error
- func (att *Attempt) ID() string
- func (att *Attempt) IsAborting(ctx context.Context) (bool, error)
- func (att *Attempt) ModTime() (time.Time, error)
- func (att *Attempt) Open(ctx context.Context) error
- func (att *Attempt) ReadDAG(_ context.Context) (*ir.DAG, error)
- func (att *Attempt) ReadOutputs(_ context.Context) (*ir.DAGRunOutputs, error)
- func (att *Attempt) ReadStatus(ctx context.Context) (*ir.DAGRunStatus, error)
- func (att *Attempt) ReadStepMessages(_ context.Context, stepName string) ([]ir.LLMMessage, error)
- func (att *Attempt) SetDAG(dag *ir.DAG)
- func (att *Attempt) Write(ctx context.Context, status ir.DAGRunStatus) error
- func (att *Attempt) WriteOutputs(_ context.Context, outputs *ir.DAGRunOutputs) error
- func (att *Attempt) WriteStepMessages(_ context.Context, stepName string, messages []ir.LLMMessage) error
- type DAGRun
- func (dr DAGRun) AttemptByDir(attemptDir string, cache *fileutil.Cache[*ir.DAGRunStatus]) (*Attempt, error)
- func (dr DAGRun) CreateAttempt(_ context.Context, ts persis.TimeInUTC, ...) (*Attempt, error)
- func (dr DAGRun) CreateSubDAGRun(_ context.Context, dagRunID string) (*DAGRun, error)
- func (dr DAGRun) FindSubDAGRun(_ context.Context, dagRunID string) (*DAGRun, error)
- func (dr DAGRun) LatestAttempt(ctx context.Context, cache *fileutil.Cache[*ir.DAGRunStatus]) (*Attempt, error)
- func (dr DAGRun) ListSubDAGRuns(ctx context.Context) ([]*DAGRun, error)
- func (dr DAGRun) Remove(ctx context.Context) error
- type DAGRunSummary
- type DataRoot
- func (dr *DataRoot) CreateDAGRun(ts persis.TimeInUTC, dagRunID string) (*DAGRun, error)
- func (dr DataRoot) Exists() bool
- func (dr *DataRoot) FindByDAGRunID(ctx context.Context, dagRunID string) (*DAGRun, error)
- func (dr DataRoot) IsEmpty() bool
- func (dr *DataRoot) Latest(ctx context.Context, itemLimit int) []*DAGRun
- func (dr *DataRoot) LatestAfter(ctx context.Context, cutoff persis.TimeInUTC) (*DAGRun, error)
- func (dr DataRoot) Remove() error
- func (dr DataRoot) RemoveOldByRuns(ctx context.Context, retentionRuns int, dryRun bool) ([]string, error)
- type Store
- func (store *Store) CompareAndSwapLatestAttemptStatus(ctx context.Context, req persis.DAGRunCompareAndSwapStatusRequest) (*ir.DAGRunStatus, bool, error)
- func (store *Store) CreateAttempt(ctx context.Context, req persis.DAGRunCreateAttemptRequest) (dagrun.Attempt, error)
- func (store *Store) FindAttempt(ctx context.Context, ref ir.DAGRunRef) (dagrun.Attempt, error)
- func (store *Store) FindSubAttempt(ctx context.Context, ref ir.DAGRunRef, subDAGRunID string) (dagrun.Attempt, error)
- func (store *Store) LatestAttempt(ctx context.Context, query persis.DAGRunLatestAttemptQuery) (dagrun.Attempt, error)
- func (store *Store) ListRetryCandidates(ctx context.Context, from persis.TimeInUTC) ([]*ir.DAGRunStatus, error)
- func (store *Store) QueryStatuses(ctx context.Context, query persis.DAGRunStatusQuery) (persis.DAGRunStatusPage, error)
- func (store *Store) RecentStatuses(ctx context.Context, dagName string, itemLimit int) ([]ir.DAGRunStatus, error)
- func (store *Store) RemoveDAGRun(ctx context.Context, req persis.DAGRunRemoveRequest) error
- func (store *Store) RemoveOldDAGRuns(ctx context.Context, req persis.DAGRunRetentionRequest) ([]ir.DAGRunRef, error)
- type StoreOption
- type WorkDirStore
- type Writer
- type WriterOption
Constants ¶
const ( // SubDAGRunsDir is the name of the directory where status files for sub dag-runs are stored. SubDAGRunsDir = "sub" // LegacySubDAGRunsDir is the previous directory where status files for sub dag-runs were stored. LegacySubDAGRunsDir = "children" // LegacySubDAGRunDirPrefix is the previous prefix for sub dag-run directories. LegacySubDAGRunDirPrefix = "child_" // DAGRunDirPrefix is the prefix for dag-run directories. DAGRunDirPrefix = "dag-run_" // AttemptDirPrefix is the prefix for attempt directories. AttemptDirPrefix = "a_" // LegacyAttemptDirPrefix is the previous prefix for attempt directories. LegacyAttemptDirPrefix = "attempt_" // SubDAGWorkDirPrefix is the prefix for sub dag-run working directories. SubDAGWorkDirPrefix = "w_" )
const CancelRequestedFlag = "CANCEL_REQUESTED"
CancelRequestedFlag is a special flag used to indicate that a cancel request has been made.
const DAGDefinition = "dag.json"
DAGDefinition is the name of the file where the DAG definition is stored.
const JSONLStatusFile = "status.jsonl"
JSONLStatusFile is the name of the status file for each dag-run. It contains the status of the dag-run in JSON Lines format. While running the dag-run, new lines are appended to this file on each status update. After finishing the run, this file will be compacted into a single JSON line file.
const MessagesDir = "messages"
MessagesDir is the directory where per-step LLM messages are stored.
const OutputsFile = "outputs.json"
OutputsFile is the name of the file where collected step outputs are stored.
Variables ¶
var ( ErrStatusFileOpen = errors.New("status file already open") ErrStatusFileNotOpen = errors.New("status file not open") ErrReadFailed = errors.New("failed to read status file") ErrWriteFailed = errors.New("failed to write to status file") ErrCompactFailed = errors.New("failed to compact status file") ErrContextCanceled = errors.New("operation canceled by context") )
Error definitions for common issues
var (
ErrInvalidDAGRunsDir = errors.New("invalid dag-runs directory name")
)
Error definitions for directory structure validation
var (
ErrWriterNotOpen = errors.New("writer is not open")
)
Functions ¶
func IsAttemptDirName ¶
func ParseStatusFile ¶
func ParseStatusFile(file string) (*ir.DAGRunStatus, error)
ParseStatusFile reads the status file and returns the last valid status. The bufferSize parameter controls the size of the read buffer.
Types ¶
type Attempt ¶
type Attempt struct {
// contains filtered or unexported fields
}
Attempt manages an append-only status file with read, write, and compaction capabilities. It provides thread-safe operations and supports metrics collection.
func NewAttempt ¶
NewAttempt creates a new Run for the specified file.
func (*Attempt) Abort ¶
Abort implements models.Attempt. It creates a flag to indicate that the attempt should be canceled.
func (*Attempt) Close ¶
Close properly closes the status file, performs compaction, and invalidates the cache. It's safe to call Close multiple times. The context can be used to cancel the operation.
func (*Attempt) Compact ¶
Compact performs file compaction to optimize storage and read performance. It's safe to call while the file is open or closed. The context can be used to cancel the operation.
func (*Attempt) Hide ¶
Hide renames the attempt directory to hide it from normal operations. It prefixes the directory name with a dot to make it hidden.
func (*Attempt) IsAborting ¶
IsAborting checks if a cancel request has been made for this attempt.
func (*Attempt) ModTime ¶
ModTime returns the last modification time of the status file. This is used to determine when the file was last updated.
func (*Attempt) Open ¶
Open initializes the status file for writing. It returns an error if the file is already open. The context can be used to cancel the operation.
func (*Attempt) ReadOutputs ¶
ReadOutputs reads the collected step outputs from outputs.json. Returns nil if the file does not exist or if the file is in old format (no metadata field).
func (*Attempt) ReadStatus ¶
ReadStatus reads the latest status from the file, using cache if available. The context can be used to cancel the operation.
func (*Attempt) ReadStepMessages ¶
ReadStepMessages reads LLM messages for a single step. Messages are stored at the dag-run level in a messages/ directory for retry persistence. Returns nil if no messages exist for the step.
func (*Attempt) SetDAG ¶
SetDAG sets the DAG for this attempt. Must be called before Open for DAG to be persisted.
func (*Attempt) Write ¶
Write adds a new status to the file. It returns an error if the file is not open or is currently being closed. The context can be used to cancel the operation.
func (*Attempt) WriteOutputs ¶
WriteOutputs writes the collected step outputs to outputs.json. If outputs is nil or has no output entries, no file is created.
func (*Attempt) WriteStepMessages ¶
func (att *Attempt) WriteStepMessages(_ context.Context, stepName string, messages []ir.LLMMessage) error
WriteStepMessages writes LLM messages for a single step. Messages are stored at the dag-run level in a messages/ directory for retry persistence.
type DAGRun ¶
type DAGRun struct {
// contains filtered or unexported fields
}
DAGRun represents a dag-run with its associated timestamp and run ID.
func NewDAGRun ¶
NewDAGRun creates a new Run instance from a directory path. It parses the directory name to extract the timestamp and dag-run ID.
func (DAGRun) AttemptByDir ¶
func (dr DAGRun) AttemptByDir(attemptDir string, cache *fileutil.Cache[*ir.DAGRunStatus]) (*Attempt, error)
AttemptByDir constructs an Attempt directly from a known attempt directory name, skipping the directory listing and sorting done by LatestAttempt.
func (DAGRun) CreateAttempt ¶
func (dr DAGRun) CreateAttempt(_ context.Context, ts persis.TimeInUTC, cache *fileutil.Cache[*ir.DAGRunStatus], attemptID string) (*Attempt, error)
CreateAttempt creates a new Attempt for the dag-run with the given timestamp. It creates a new Attempt directory and initializes a record within it. If attemptID is provided, it uses that ID instead of generating a new one.
func (DAGRun) CreateSubDAGRun ¶
CreateSubDAGRun creates a new sub dag-run with the given timestamp and dag-run ID.
func (DAGRun) FindSubDAGRun ¶
FindSubDAGRun searches for a sub dag-run by its run ID.
func (DAGRun) LatestAttempt ¶
func (dr DAGRun) LatestAttempt(ctx context.Context, cache *fileutil.Cache[*ir.DAGRunStatus]) (*Attempt, error)
LatestAttempt returns the most recent Attempt for the dag-run. It searches through all run directories and returns the first valid Attempt found. It skips hidden attempts (dequeued ones).
func (DAGRun) ListSubDAGRuns ¶
type DAGRunSummary ¶
type DAGRunSummary struct {
LatestAttemptDir string
Status ir.Status
StartedAtUnix int64
FinishedAtUnix int64
Labels []string
Name string
DagRunID string
WorkerID string
LeaseAt int64
Params string
QueuedAt string
ScheduleTime string
TriggerType ir.TriggerType
TriggerActor string
CreatedAt int64
AttemptID string
AutoRetryCount int
ParentName string
ParentID string
AutoRetryLimit int
AutoRetryInterval time.Duration
AutoRetryBackoff float64
AutoRetryMaxInterval time.Duration
ProcGroup string
DefinitionID string
ArchiveDir string
}
DAGRunSummary holds pre-loaded summary data from a day index. When non-nil, it allows filtering and constructing list responses without reading status.jsonl.
type DataRoot ¶
type DataRoot struct {
dirlock.DirLock // Directory lock for concurrent access
// contains filtered or unexported fields
}
DataRoot manages the directory structure for run history data. It handles the organization of run data in a hierarchical structure based on year, month, and day.
func NewDataRoot ¶
NewDataRoot creates a new DataRoot instance for managing a DAG's run history. It sanitizes the DAG name to create a safe directory structure and applies any provided options.
Parameters:
- baseDir: The base directory where all DAG data is stored
- dagName: The name of the DAG (can be a path to a YAML file)
Returns:
- A configured DataRoot instance
func NewDataRootWithArtifactDir ¶
NewDataRootWithArtifactDir creates a new DataRoot with an explicit trusted artifact root.
func (*DataRoot) CreateDAGRun ¶
CreateDAGRun creates a new dag-run directory with the specified timestamp and ID. The directory structure follows the pattern: year/month/day/run-YYYYMMDD_HHMMSS_dagRunID
func (*DataRoot) FindByDAGRunID ¶
FindByDAGRunID locates a dag-run by its ID. It scans the year/month/day hierarchy in reverse chronological order and returns the first exact match, which preserves the "newest run wins" behavior without materializing and sorting all matches across the full history tree.
func (DataRoot) IsEmpty ¶
IsEmpty checks if the dag-runs directory exists and contains no dag-run directories. Returns true if the directory doesn't exist or contains no dag-runs.
func (*DataRoot) Latest ¶
Latest returns the most recent dag-runs up to the specified limit. It searches through the dag-run directories and returns them sorted by timestamp (newest first).
func (*DataRoot) LatestAfter ¶
LatestAfter returns the most recent dag-run that occurred after the specified cutoff time. Returns ErrNoStatusData if no dag-run is found or if the latest run is before the cutoff.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store manages DAG run status files on the local filesystem.
func NewStore ¶ added in v2.14.0
func NewStore(baseDir string, opts ...StoreOption) *Store
NewStore creates filesystem DAG-run storage.
func (*Store) CompareAndSwapLatestAttemptStatus ¶
func (store *Store) CompareAndSwapLatestAttemptStatus( ctx context.Context, req persis.DAGRunCompareAndSwapStatusRequest, ) (*ir.DAGRunStatus, bool, error)
func (*Store) CreateAttempt ¶
func (store *Store) CreateAttempt(ctx context.Context, req persis.DAGRunCreateAttemptRequest) (dagrun.Attempt, error)
CreateAttempt creates an attempt within a root or child DAG run.
func (*Store) FindAttempt ¶
FindAttempt finds the latest attempt by DAG-run ID.
func (*Store) FindSubAttempt ¶
func (store *Store) FindSubAttempt(ctx context.Context, ref ir.DAGRunRef, subDAGRunID string) (dagrun.Attempt, error)
FindSubAttempt finds a sub dag-run by its ID. It returns the latest attempt for the specified sub DAG-run ID.
func (*Store) LatestAttempt ¶
func (store *Store) LatestAttempt(ctx context.Context, query persis.DAGRunLatestAttemptQuery) (dagrun.Attempt, error)
LatestAttempt returns the newest visible attempt matching the query.
func (*Store) ListRetryCandidates ¶
func (*Store) QueryStatuses ¶ added in v2.14.0
func (store *Store) QueryStatuses(ctx context.Context, query persis.DAGRunStatusQuery) (persis.DAGRunStatusPage, error)
QueryStatuses executes a normalized status query.
func (*Store) RecentStatuses ¶ added in v2.14.0
func (store *Store) RecentStatuses(ctx context.Context, dagName string, itemLimit int) ([]ir.DAGRunStatus, error)
RecentStatuses returns the newest readable status for recent DAG runs.
func (*Store) RemoveDAGRun ¶
RemoveDAGRun removes a DAG run and all of its attempts.
func (*Store) RemoveOldDAGRuns ¶
func (store *Store) RemoveOldDAGRuns(ctx context.Context, req persis.DAGRunRetentionRequest) ([]ir.DAGRunRef, error)
RemoveOldDAGRuns removes final runs outside a normalized retention policy.
type StoreOption ¶ added in v2.14.0
type StoreOption func(*options)
StoreOption configures filesystem DAG-run storage.
func WithArtifactDir ¶
func WithArtifactDir(dir string) StoreOption
WithArtifactDir sets the trusted root for artifact cleanup operations.
func WithHistoryFileCache ¶
func WithHistoryFileCache(cache *fileutil.Cache[*ir.DAGRunStatus]) StoreOption
WithHistoryFileCache sets the file cache for Store.
type WorkDirStore ¶ added in v2.14.0
type WorkDirStore struct {
// contains filtered or unexported fields
}
WorkDirStore manages file-backed DAG-run work directories.
func NewWorkDirStore ¶ added in v2.14.0
func NewWorkDirStore(rootDir, historyDir string) *WorkDirStore
NewWorkDirStore creates a work-directory store rooted at rootDir. Existing work directories nested under historyDir remain accessible.
func (*WorkDirStore) Materialize ¶ added in v2.14.0
func (s *WorkDirStore) Materialize(ctx context.Context, ref dagrun.WorkDirRef) (string, error)
func (*WorkDirStore) Remove ¶ added in v2.14.0
func (s *WorkDirStore) Remove(_ context.Context, ref dagrun.WorkDirRef) error
func (*WorkDirStore) Snapshot ¶ added in v2.14.0
func (*WorkDirStore) Snapshot(context.Context, dagrun.WorkDirRef, string) error
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
func NewWriter ¶
func NewWriter(target string, opts ...WriterOption) *Writer
NewWriter creates a new Writer instance for the specified target file path.
func (*Writer) Close ¶
Close flushes any buffered data and closes the underlying file. It's safe to call close multiple times.
type WriterOption ¶
type WriterOption func(*Writer)
WriterOption defines functional options for configuring a Writer.