Help us shape the future of Go! Take the 2026 Go Developer Survey

schedule

package
v0.4.45 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCron added in v0.1.3

func NewCron(cfg CronConfig, deps CronDeps) (capschedule.Runtime, error)

NewCron registers schedule/cron: Resident calendar scheduler over a shared job registry.

Best practices:

  • Point tool/schedule at the same registry instance, or agent jobs never fire.
  • Script jobs need workspace and shell deps; prompt jobs only need the registry.
  • Missed boundaries are skipped, not backfilled.

func NewFile

func NewFile(cfg FileConfig, deps FileDeps) (capschedule.Registry, error)

NewFile registers schedule/file: Durable cron job table, shared by schedule/cron and tool/capschedule.

Best practices:

  • Point schedule/cron and tool/schedule at one instance, or the agent will schedule jobs nothing fires.
  • Jobs carry a source: config jobs are reconciled against the preset on every start, agent jobs are left alone.
  • Writes go through a temp file and rename, so a process killed mid-write leaves no truncated table.

func NewMulti added in v0.1.10

func NewMulti(cfg MultiConfig, deps MultiDeps) (schedule.Registry, error)

NewMulti registers schedule/multi: One shared schedule.json with per-channel list/remove filtering.

Types

type Cron added in v0.1.3

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

Cron watches a shared registry and submits due jobs as inbound turns.

func (*Cron) SetClockForTest added in v0.1.3

func (c *Cron) SetClockForTest(now func() time.Time, wait func(context.Context, time.Duration) error)

SetClockForTest replaces the clock and wait so cron behaviour can be asserted without real waiting. Test-only.

func (*Cron) SetLoopHookForTest added in v0.3.25

func (c *Cron) SetLoopHookForTest(hook func())

SetLoopHookForTest runs hook at the top of each Start loop iteration. Test-only.

func (*Cron) Start added in v0.1.3

func (c *Cron) Start(ctx context.Context, submit capschedule.SubmitFunc) error

func (*Cron) Stop added in v0.1.3

func (c *Cron) Stop(context.Context) error

type CronConfig added in v0.1.3

type CronConfig struct {
	// Jobs are reconciled into the registry on every start with source=config.
	Jobs []CronJobSpec `json:"jobs"`
	// SessionMode is stateless (default), reuse, or fixed.
	SessionMode string `json:"sessionMode"`
	// SessionID is the id prefix used for inbound turns.
	SessionID string `json:"sessionId"`
	// PollSeconds bounds the wait before rechecking the registry for job changes.
	// Defaults to 30.
	PollSeconds int `json:"pollSeconds"`
	// MissedGraceSeconds is how long a missed one-shot job is still fired.
	// Older one-shots are marked stale instead of backfilled. Defaults to 300.
	MissedGraceSeconds int `json:"missedGraceSeconds"`
	// PromptTemplate replaces the default preamble prepended to every fired
	// prompt. Use it to name a host-specific tool; leave it empty and the
	// default mentions no tool at all.
	PromptTemplate string `json:"promptTemplate"`
}

func (*CronConfig) SetDefaults added in v0.3.48

func (c *CronConfig) SetDefaults()

SetDefaults implements pluginkit.Defaulter.

func (*CronConfig) Validate added in v0.3.48

func (c *CronConfig) Validate() error

Validate implements pluginkit.Validator.

type CronDeps added in v0.1.3

type CronDeps struct {
	Schedule  capschedule.Registry `json:"schedule"`
	Workspace workspace.Service    `json:"workspace,omitempty"`
	Shell     shell.Executor       `json:"shell,omitempty"`
	Engine    capschedule.Engine   `json:"engine"`
}

type CronJobSpec added in v0.1.3

type CronJobSpec struct {
	ID     string `json:"id"`
	Cron   string `json:"cron"`
	Prompt string `json:"prompt,omitempty"`
	Script string `json:"script,omitempty"`
	Note   string `json:"note,omitempty"`
	// DeliverTo is the destination session id, e.g.
	// "lark:oc_xxx:u:ou_yyy" or "chat-api:default:t:conv_1". When set, the
	// fired turn delivers its answer there; when empty the turn still runs but
	// has no user-facing destination (metadata-only jobs).
	DeliverTo string `json:"deliverTo,omitempty"`
	// Platform overrides the delivery protocol; defaults to the protocol
	// parsed from DeliverTo.
	Platform string `json:"platform,omitempty"`
	// Owner opens the scope: only Owner answers the permission prompts of a
	// job that routes back to an interactive platform.
	Owner string `json:"owner,omitempty"`
	// AgentID pins the fire to one agent; empty uses the loop default.
	AgentID string `json:"agentId,omitempty"`
}

CronJobSpec is one config-declared cron job. Prompt and script are mutually exclusive; script runs without an agent turn.

Config jobs used to carry no destination, so a fired job degraded to the synthetic "schedule" platform and its result could never be delivered. Give the spec a delivery target (an id.list session id) and optionally an owner and agent, and the fire routes exactly like an agent-created job.

type FileConfig

type FileConfig struct {
	// Path is JSON file holding the jobs, resolved through the workspace.
	Path string `json:"path"`
}

func (*FileConfig) SetDefaults added in v0.3.48

func (c *FileConfig) SetDefaults()

SetDefaults implements pluginkit.Defaulter.

type FileDeps

type FileDeps struct {
	FS     filesystem.Service `json:"fs"`
	Engine capschedule.Engine `json:"engine"`
}

type MultiConfig added in v0.1.10

type MultiConfig struct {
	// Path is the shared schedule file, default global:schedule.json.
	Path string `json:"path"`
}

func (*MultiConfig) SetDefaults added in v0.3.48

func (c *MultiConfig) SetDefaults()

SetDefaults implements pluginkit.Defaulter.

type MultiDeps added in v0.1.10

type MultiDeps struct {
	FS     filesystem.Service `json:"fs"`
	Engine schedule.Engine    `json:"engine"`
}

Jump to

Keyboard shortcuts

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