Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultStorePath(home string) string
- func PauseJobTimeout(ctx context.Context) (resume func())
- type CronJob
- type CronJobState
- type CronPayload
- type CronSchedule
- type CronService
- func (cs *CronService) AddJob(name string, schedule CronSchedule, message string, channel, to string, ...) (*CronJob, error)
- func (cs *CronService) DeleteJob(jobID string) (bool, error)
- func (cs *CronService) EnableJob(jobID string, enabled bool) *CronJob
- func (cs *CronService) GetJob(jobID string) (*CronJob, bool)
- func (cs *CronService) ListJobs(includeDisabled bool) []CronJob
- func (cs *CronService) Load() error
- func (cs *CronService) LoadErr() error
- func (cs *CronService) RemoveJob(jobID string) bool
- func (cs *CronService) SetJobEnabled(jobID string, enabled bool) (*CronJob, error)
- func (cs *CronService) SetOnJob(handler JobHandler)
- func (cs *CronService) SetOnJobContext(handler JobHandlerContext)
- func (cs *CronService) Start() error
- func (cs *CronService) Status() map[string]any
- func (cs *CronService) Stop()
- func (cs *CronService) UpdateJob(job *CronJob) error
- type CronStore
- type JobHandler
- type JobHandlerContext
- type JobOption
- type Option
Constants ¶
const ( // MinEveryInterval is the shortest interval a job may repeat at. Every run // of an agent-turn job is a model call, so a seconds-level schedule is a // cost and flooding risk rather than a feature. MinEveryInterval = time.Minute // MaxJobsPerChat bounds the jobs one chat (channel and recipient) may hold. MaxJobsPerChat = 50 // MaxJobs bounds the whole store. MaxJobs = 500 // DefaultJobTimeout bounds one run when no timeout is configured. DefaultJobTimeout = 10 * time.Minute )
Variables ¶
var ( // ErrJobNotFound is returned for an unknown job ID. ErrJobNotFound = errors.New("job not found") // ErrServiceStopped is returned by a service that was stopped: after a // reload its successor owns the store, and a late write would undo that // successor's changes. ErrServiceStopped = errors.New("cron service is stopped") )
Functions ¶
func DefaultStorePath ¶
DefaultStorePath is where the cron store lives: <home>/state/cron/jobs.json, outside the workspace the agent's file tools can write.
func PauseJobTimeout ¶
PauseJobTimeout stops counting the job timeout of the run ctx belongs to until the returned function is called: a run waiting for the owner's approval doesn't use up its time. Outside a job run it does nothing.
Types ¶
type CronJob ¶
type CronJob struct {
ID string `json:"id"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
Schedule CronSchedule `json:"schedule"`
Payload CronPayload `json:"payload"`
State CronJobState `json:"state"`
CreatedAtMS int64 `json:"createdAtMs"`
UpdatedAtMS int64 `json:"updatedAtMs"`
DeleteAfterRun bool `json:"deleteAfterRun"`
}
type CronJobState ¶
type CronPayload ¶
type CronSchedule ¶
type CronSchedule struct {
Kind string `json:"kind"`
AtMS *int64 `json:"atMs,omitempty"`
EveryMS *int64 `json:"everyMs,omitempty"`
Expr string `json:"expr,omitempty"`
TZ string `json:"tz,omitempty"`
}
func (CronSchedule) Validate ¶
func (s CronSchedule) Validate() error
Validate reports why a schedule can't be used: an unknown kind, a missing or past time, an interval below MinEveryInterval, an invalid cron expression or time zone, or a cron expression that fires more than once a minute.
type CronService ¶
type CronService struct {
// contains filtered or unexported fields
}
func NewCronService ¶
func NewCronService(storePath string, onJob JobHandler, opts ...Option) *CronService
func OpenCronService ¶
func OpenCronService(storePath string, onJob JobHandler, opts ...Option) (*CronService, error)
OpenCronService is NewCronService that reports a store it can't load.
func (*CronService) AddJob ¶
func (cs *CronService) AddJob( name string, schedule CronSchedule, message string, channel, to string, opts ...JobOption, ) (*CronJob, error)
func (*CronService) DeleteJob ¶
func (cs *CronService) DeleteJob(jobID string) (bool, error)
DeleteJob is RemoveJob that reports why nothing was removed.
func (*CronService) EnableJob ¶
func (cs *CronService) EnableJob(jobID string, enabled bool) *CronJob
func (*CronService) ListJobs ¶
func (cs *CronService) ListJobs(includeDisabled bool) []CronJob
func (*CronService) Load ¶
func (cs *CronService) Load() error
func (*CronService) LoadErr ¶
func (cs *CronService) LoadErr() error
LoadErr reports why the store couldn't be loaded, or nil.
func (*CronService) RemoveJob ¶
func (cs *CronService) RemoveJob(jobID string) bool
func (*CronService) SetJobEnabled ¶
func (cs *CronService) SetJobEnabled(jobID string, enabled bool) (*CronJob, error)
SetJobEnabled is EnableJob that reports failures: an unknown job, a one-time job whose time has passed, or a store that can't be written.
func (*CronService) SetOnJob ¶
func (cs *CronService) SetOnJob(handler JobHandler)
func (*CronService) SetOnJobContext ¶
func (cs *CronService) SetOnJobContext(handler JobHandlerContext)
SetOnJobContext sets a handler that receives the job's context; it takes precedence over SetOnJob.
func (*CronService) Start ¶
func (cs *CronService) Start() error
func (*CronService) Status ¶
func (cs *CronService) Status() map[string]any
func (*CronService) Stop ¶
func (cs *CronService) Stop()
Stop ends scheduling and cancels running jobs. A stopped service never writes the store again.
func (*CronService) UpdateJob ¶
func (cs *CronService) UpdateJob(job *CronJob) error
type JobHandler ¶
type JobHandlerContext ¶
JobHandlerContext runs a job with a context that carries the job timeout and is cancelled when the service stops.
type JobOption ¶
type JobOption func(*CronPayload)
JobOption sets an optional part of a job AddJob creates.
func WithCommand ¶
WithCommand makes the job run command rather than an agent turn. The job is written with it at once, so it never runs, nor stays, without it.
type Option ¶
type Option func(*CronService)
Option configures a CronService.
func WithJobTimeout ¶
WithJobTimeout bounds one job run; zero or less keeps DefaultJobTimeout.