schedule

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package schedule parses cron expressions and runs the ledger's jobs when they come due. The parser handles standard five-field cron (minute hour day-of-month month day-of-week) plus a few @macros and an @every duration form, which covers what the agent and the cron command need without pulling in a dependency.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Tool

func Tool(st *store.Store, channel, chat string) tool.Tool

Tool lets the agent schedule its own follow-up work. It is bound to one chat: the job it creates runs later as a background turn in this same conversation and delivers its result here. The router builds a fresh tool per turn so channel and chat always match the caller.

Scheduling writes a row to the ledger, so the tool is a write action and the policy gate treats it as one.

Types

type Poster

type Poster interface {
	Post(ctx context.Context, chat, text string) error
}

Poster pushes a message to a chat on its own, outside a reply. The scheduler needs it to deliver background results. A front door that can only answer when spoken to (the web chat, which has no durable client to push to) simply does not provide one, and its jobs run and record but deliver nothing.

type RunFunc

type RunFunc func(ctx context.Context, channel, chat, prompt string) (string, error)

RunFunc executes a job's prompt as a background turn and returns the assistant's text. The router supplies it.

type Schedule

type Schedule interface {
	Next(after time.Time) time.Time
}

Schedule reports the next time a job should run after a given instant.

func Parse

func Parse(spec string) (Schedule, error)

Parse turns a spec into a Schedule. Accepted forms:

@every 30m         a fixed interval after the previous run
@hourly @daily @midnight @weekly @monthly @yearly
5 * * * *          standard five-field cron, in the local time zone

type Scheduler

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

Scheduler ticks once a minute, runs the jobs that have come due, records each run, and delivers any output to the job's channel.

func New

func New(st *store.Store, run RunFunc, posters map[string]Poster) *Scheduler

New builds a scheduler. posters maps a channel name to the thing that can push a message there; a job whose channel has no poster still runs and is recorded, its output just is not delivered.

func (*Scheduler) Run

func (s *Scheduler) Run(ctx context.Context) error

Run checks due jobs immediately, then every minute, until ctx is cancelled. The startup check is the missed-tick catch-up: a job that came due while the process was down runs once now, no matter how many ticks it missed.

Jump to

Keyboard shortcuts

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