store

package
v0.629.4 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package store provides task persistence and retrieval.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileStore

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

FileStore implements Store using a JSON file for persistence.

func NewFileStore

func NewFileStore(path string) (*FileStore, error)

NewFileStore creates a new file-based store.

func (*FileStore) ClaimForDispatch added in v0.629.4

func (fs *FileStore) ClaimForDispatch(id, owner string, expires time.Time) (bool, error)

ClaimForDispatch atomically reserves a pending task for owner. The claim is won only when the task exists, is still pending, and is not already held by a live (unexpired) lease — an expired lease is stolen, which is how a task stranded by a dispatcher crash becomes dispatchable again. The whole check and write happen under the store lock so two concurrent dispatchers can never both win.

func (*FileStore) Close

func (fs *FileStore) Close() error

Close stops the background saver and performs final save. Safe to call multiple times.

func (*FileStore) Delete

func (fs *FileStore) Delete(id string) error

Delete removes a task by ID.

func (*FileStore) ForceSave

func (fs *FileStore) ForceSave() error

ForceSave immediately persists all tasks to disk.

func (*FileStore) Get

func (fs *FileStore) Get(id string) (*models.Task, error)

Get retrieves a task by ID.

func (*FileStore) List

func (fs *FileStore) List(filter ListFilter) ([]*models.Task, error)

List retrieves tasks matching the filter.

func (*FileStore) ListByParentSession added in v0.601.2

func (fs *FileStore) ListByParentSession(sessionID string) ([]*models.Task, error)

ListByParentSession returns all tasks whose ParentSessionID matches the given session id, newest first. It is a thin convenience wrapper over List.

func (*FileStore) ReleaseClaim added in v0.629.4

func (fs *FileStore) ReleaseClaim(id string) error

ReleaseClaim drops a task's dispatch claim. A missing task is not an error: releasing is cleanup, and cleanup must not fail because the thing being cleaned up is already gone.

func (*FileStore) Reload

func (fs *FileStore) Reload() error

Reload reloads the store from disk.

func (*FileStore) Save

func (fs *FileStore) Save(task *models.Task) error

Save stores or updates a task.

func (*FileStore) UpdateStatus

func (fs *FileStore) UpdateStatus(id string, status models.TaskStatus) error

UpdateStatus updates only the status of a task.

type ListFilter

type ListFilter struct {
	Status []models.TaskStatus
	Tags   []string
	Limit  int
	Offset int
	// ParentSessionID, when non-empty, restricts results to tasks whose
	// ParentSessionID matches exactly. Used for delegation correlation queries.
	ParentSessionID string
}

ListFilter defines criteria for listing tasks.

type Store

type Store interface {
	Save(task *models.Task) error
	Get(id string) (*models.Task, error)
	List(filter ListFilter) ([]*models.Task, error)
	// ListByParentSession returns tasks correlated to the given parent agent
	// session id (see Task.ParentSessionID). Used by delegation phases to find
	// the tasks spawned by a session; no consumer reads it yet.
	ListByParentSession(sessionID string) ([]*models.Task, error)
	Delete(id string) error
	UpdateStatus(id string, status models.TaskStatus) error
	// ClaimForDispatch atomically reserves a pending task for execution by owner
	// and returns whether the claim was won. It is the compare-and-set that makes
	// dispatch safe when several readiness evaluations race for the same task
	// (two dependencies completing at once used to start it twice).
	ClaimForDispatch(id, owner string, expires time.Time) (bool, error)
	// ReleaseClaim drops a task's dispatch claim. Safe to call on a task that
	// holds none.
	ReleaseClaim(id string) error
	Close() error
}

Store defines the interface for task storage.

Jump to

Keyboard shortcuts

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