schedule

package
v0.15.7 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusActive = "active"
	StatusPaused = "paused"

	// MinInterval is a floor against runaway wake loops, not a technical
	// limit: every fire is a model turn, so tighter polling belongs in a
	// pre-check script or a backgrounded watcher, not the schedule itself.
	// Checked when a task is created, not when an existing one is evaluated.
	MinInterval = 10 * time.Second

	MaxJitter = 15 * time.Minute
)

Variables

This section is empty.

Functions

func Find

func Find(tasks []Task, id string) (int, error)

Find resolves a task reference the model typed back: an exact id, or an unambiguous prefix of one. Ambiguous prefixes are an error rather than a coin flip on which task gets paused or removed.

func IsDue

func IsDue(t Task, now time.Time) bool

func IsOneTime

func IsOneTime(sched string) bool

func NextAttempt

func NextAttempt(t Task, now time.Time) time.Time

NextAttempt is NextRun pushed out by failure backoff: consecutive pre-check failures space retries exponentially (2m, 4m, ... capped at an hour) so a broken gate on a tight interval cannot wake-loop the agent.

func NextRun

func NextRun(t Task, now time.Time) time.Time

func OnceTime

func OnceTime(sched string) (time.Time, bool)

func Relative

func Relative(next, now time.Time) string

Relative renders a next-run time the way every surface shows it: "overdue", "in 42m", "in 3h5m".

func RunGate

func RunGate(ctx context.Context, dir, script string) (bool, string, error)

RunGate executes a task's pre-check script. It reports whether the agent should be woken; on script failure it fails open so the agent can fix it, and returns the error so the scheduler can back off repeat failures.

func Tools

func Tools(store Store) []tool.Tool

Types

type FileStore

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

func NewFileStore

func NewFileStore(dir string) *FileStore

func (*FileStore) Exists

func (s *FileStore) Exists() bool

func (*FileStore) List

func (s *FileStore) List() ([]Task, error)

func (*FileStore) Mutate

func (s *FileStore) Mutate(fn func([]Task) ([]Task, error)) error

func (*FileStore) Path

func (s *FileStore) Path() string

type MemoryStore

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

func NewMemoryStore

func NewMemoryStore() *MemoryStore

func (*MemoryStore) Changed

func (s *MemoryStore) Changed() <-chan struct{}

Changed signals (coalesced, one buffered tick) after every successful Mutate, so a scheduler sleeping until the next known due time can wake up and re-plan when tasks are added or removed mid-sleep.

func (*MemoryStore) List

func (s *MemoryStore) List() ([]Task, error)

func (*MemoryStore) Mutate

func (s *MemoryStore) Mutate(fn func([]Task) ([]Task, error)) error

type Store

type Store interface {
	List() ([]Task, error)
	Mutate(fn func([]Task) ([]Task, error)) error
}

Store holds a set of scheduled tasks. FileStore persists them across restarts (the building block for durable schedules); MemoryStore is scoped to a single interactive session and dies with it.

type Task

type Task struct {
	ID        string     `yaml:"id"`
	Prompt    string     `yaml:"prompt"`
	Schedule  string     `yaml:"schedule"`
	Script    string     `yaml:"script,omitempty"`
	Status    string     `yaml:"status"`
	CreatedAt time.Time  `yaml:"created_at"`
	LastRun   *time.Time `yaml:"last_run,omitempty"`

	Failures    int        `yaml:"failures,omitempty"`
	LastAttempt *time.Time `yaml:"last_attempt,omitempty"`
}

func NewTask

func NewTask(prompt, sched string) (Task, error)

Jump to

Keyboard shortcuts

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