scheduler

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package scheduler provides cron-based scheduling for agent runs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RunFunc

type RunFunc func(ctx context.Context, agentID, input, sessionID string) error

RunFunc is called when a schedule fires. It receives the agent ID, input, and session ID.

type RunRecord

type RunRecord struct {
	ID         string    `json:"id"`
	ScheduleID string    `json:"schedule_id"`
	AgentID    string    `json:"agent_id"`
	SessionID  string    `json:"session_id"`
	Input      string    `json:"input"`
	Status     string    `json:"status"` // success, error
	Error      string    `json:"error,omitempty"`
	StartedAt  time.Time `json:"started_at"`
	FinishedAt time.Time `json:"finished_at"`
}

RunRecord is a historical record of a scheduled run.

type Schedule

type Schedule struct {
	ID         string    `json:"id"`
	AgentID    string    `json:"agent_id"`
	CronExpr   string    `json:"cron_expr"`
	Input      string    `json:"input"`
	NewSession bool      `json:"new_session"` // true = new session per run, false = reuse
	SessionID  string    `json:"session_id,omitempty"`
	Enabled    bool      `json:"enabled"`
	CreatedAt  time.Time `json:"created_at"`
	LastRunAt  time.Time `json:"last_run_at,omitempty"`
	NextRunAt  time.Time `json:"next_run_at,omitempty"`
	RunCount   int64     `json:"run_count"`
}

Schedule defines a cron-scheduled agent run.

type Scheduler

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

Scheduler manages cron-scheduled agent runs.

func New

func New(runFn RunFunc) *Scheduler

New creates a new Scheduler. runFn is called when a schedule fires.

func (*Scheduler) Add

func (s *Scheduler) Add(agentID, cronExpr, input string, newSession bool) (*Schedule, error)

Add creates a new schedule.

func (*Scheduler) Get

func (s *Scheduler) Get(id string) (*Schedule, error)

Get returns a schedule by ID.

func (*Scheduler) History

func (s *Scheduler) History(scheduleID string) []RunRecord

History returns run records for a schedule.

func (*Scheduler) List

func (s *Scheduler) List() []*Schedule

List returns all schedules.

func (*Scheduler) Remove

func (s *Scheduler) Remove(id string) error

Remove deletes a schedule.

func (*Scheduler) Start

func (s *Scheduler) Start(ctx context.Context)

Start begins the scheduler loop. It checks for due schedules every tick interval.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop halts the scheduler loop.

func (*Scheduler) WithTickInterval

func (s *Scheduler) WithTickInterval(d time.Duration) *Scheduler

WithTickInterval sets the polling interval (for testing). Default is 1 minute.

Jump to

Keyboard shortcuts

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