scheduler

package
v0.109.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package scheduler provides cron-driven background execution of agent prompts on behalf of the Schedule tool. Jobs are persisted as YAML files under the configured storage directory and hot-reloaded by Service via fsnotify.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("scheduled job not found")

ErrNotFound is returned when a job ID does not exist in the store.

Functions

func IDFromPath

func IDFromPath(path string) string

IDFromPath returns the job ID derived from a YAML file path. Returns the empty string when the path is not a job file.

func ParseCron

func ParseCron(expr string) error

ParseCron is a package-level helper for callers that don't have a Service instance yet (e.g. validation in the Schedule tool's Validate method).

Types

type ChannelLookupFn

type ChannelLookupFn func(name string) domain.Channel

ChannelLookupFn returns the registered Channel for a name, or nil if unknown.

type ExecCommandFn

type ExecCommandFn func(ctx context.Context, name string, args ...string) *exec.Cmd

ExecCommandFn matches exec.CommandContext. Exposed for tests.

type Options

type Options struct {
	Store         *Store
	ChannelLookup ChannelLookupFn
	// ExecCommand defaults to exec.CommandContext when nil.
	ExecCommand ExecCommandFn
	// BinaryPath defaults to os.Args[0] (current binary) when empty.
	BinaryPath string
}

Options bundles dependencies and configuration for NewService.

type Service

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

Service runs scheduled jobs inside the channels-manager daemon. Jobs are loaded from the on-disk Store, registered with a robfig/cron scheduler, and hot-reloaded when the storage directory changes (via fsnotify).

On fire, a fresh `infer agent --session-id <uuid>` subprocess is spawned — every fire gets a brand-new session, so no context carries between runs. Each assistant line emitted by the agent is forwarded to the configured channel/recipient via the in-process channel lookup.

func NewService

func NewService(opts Options) (*Service, error)

NewService constructs a Service. Returns an error if required deps are missing.

func (*Service) JobIDs

func (s *Service) JobIDs() []string

JobIDs returns the set of currently-registered job IDs (test helper).

func (*Service) LoadJobs

func (s *Service) LoadJobs() error

LoadJobs replaces all currently-registered cron entries with the jobs currently on disk. Safe to call repeatedly.

func (*Service) ParseCron

func (s *Service) ParseCron(expr string) error

ParseCron exposes the same parser the service uses, so the Schedule tool can validate cron expressions identically before persisting them.

func (*Service) Start

func (s *Service) Start(ctx context.Context) error

Start initialises the cron scheduler, loads all jobs from disk, and begins watching the storage directory for changes.

func (*Service) Stop

func (s *Service) Stop(ctx context.Context) error

Stop halts the watcher and waits for in-flight cron entries to finish (up to the deadline embedded in ctx, if any).

type Store

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

Store persists ScheduledJob records as YAML files in a directory. One file per job, named "<id>.yaml". Writes are atomic (write to .tmp, then rename) so partial writes never expose half-formed YAML to the daemon's fsnotify watcher.

func NewStore

func NewStore(dir string) (*Store, error)

NewStore creates the storage directory if it does not exist and returns a Store ready to use.

func (*Store) Delete

func (s *Store) Delete(id string) error

Delete removes a job by ID. Returns ErrNotFound if it did not exist.

func (*Store) Dir

func (s *Store) Dir() string

Dir returns the storage directory path.

func (*Store) List

func (s *Store) List() ([]*domain.ScheduledJob, []error)

List returns all jobs sorted by CreatedAt ascending. Files that fail to parse are skipped (the corresponding errors are returned alongside the successfully-loaded jobs).

func (*Store) Load

func (s *Store) Load(id string) (*domain.ScheduledJob, error)

Load reads a single job by ID. Returns ErrNotFound if the file does not exist.

func (*Store) LoadFromPath

func (s *Store) LoadFromPath(path string) (*domain.ScheduledJob, error)

LoadFromPath reads a job from an explicit path. Useful when the fsnotify watcher reports a change without a clean ID extraction.

func (*Store) Path

func (s *Store) Path(id string) string

Path returns the YAML path for a given job ID.

func (*Store) Save

func (s *Store) Save(job *domain.ScheduledJob) error

Save writes the job to disk atomically.

Jump to

Keyboard shortcuts

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