Documentation
¶
Overview ¶
Package cron 实现 Golem 的定时任务 (Cron Jobs) 调度系统。
Index ¶
- type Job
- type JobHandler
- type JobState
- type Payload
- type Schedule
- type Service
- func (s *Service) AddJob(name, message string, schedule Schedule, channel, chatID string, deliver bool) (*Job, error)
- func (s *Service) EnableJob(id string, enabled bool) (*Job, error)
- func (s *Service) GetJob(id string) (*Job, bool)
- func (s *Service) ListJobs(includeDisabled bool) []*Job
- func (s *Service) RemoveJob(id string) error
- func (s *Service) RunJob(id string) (*Job, error)
- func (s *Service) Start() error
- func (s *Service) Status() map[string]any
- func (s *Service) Stop()
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Job ¶
type Job struct {
ID string `json:"id"` // 唯一标识符
Name string `json:"name"` // 任务显示名称
Enabled bool `json:"enabled"` // 是否处于启用状态
Schedule Schedule `json:"schedule"` // 调度计划
Payload Payload `json:"payload"` // 待执行载荷
State JobState `json:"state"` // 运行状态
CreatedAtMS int64 `json:"created_at_ms"` // 创建时间
UpdatedAtMS int64 `json:"updated_at_ms"` // 更新时间
DeleteAfterRun bool `json:"delete_after_run,omitempty"` // 执行完成后是否自动从存储中删除
}
Job 表示一个完整的定时任务配置及其状态。
func (*Job) ScheduleDescription ¶
ScheduleDescription 返回任务调度计划的人类可读描述。
type JobState ¶
type JobState struct {
NextRunAtMS *int64 `json:"next_run_at_ms,omitempty"` // 下次预定执行时间
LastRunAtMS *int64 `json:"last_run_at_ms,omitempty"` // 最近一次执行时间
LastStatus string `json:"last_status,omitempty"` // 最近执行状态 ("ok", "error")
LastError string `json:"last_error,omitempty"` // 最近一次执行产生的错误消息
}
JobState 维护任务的实时运行状态。
type Payload ¶
type Payload struct {
Kind string `json:"kind"` // 载荷类型(如 "agent_turn")
Message string `json:"message"` // 发送给 Agent 的指令内容
Channel string `json:"channel"` // 目标回复通道名称
ChatID string `json:"chat_id"` // 目标聊天 ID
Deliver bool `json:"deliver"` // 是否直接交付结果而跳过 Agent 思考
}
Payload 描述定时任务触发时需要执行的具体操作。
type Schedule ¶
type Schedule struct {
Kind string `json:"kind"` // 调度类型:"at" (单次), "every" (间隔), "cron" (表达式)
AtMS *int64 `json:"at_ms,omitempty"` // 单次执行的时间戳(毫秒)
EveryMS *int64 `json:"every_ms,omitempty"` // 执行间隔时长(毫秒)
Expr string `json:"expr,omitempty"` // 5 段式 Cron 表达式
}
Schedule 定义任务触发的计划规则。
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service 负责管理定时任务的生命周期,并使用轮询循环 (Ticker) 进行调度执行。
func NewService ¶
func NewService(storePath string, handler JobHandler) *Service
NewService 创建并返回一个由指定文件路径支持的定时任务服务。
func (*Service) AddJob ¶
func (s *Service) AddJob(name, message string, schedule Schedule, channel, chatID string, deliver bool) (*Job, error)
AddJob 创建并持久化一个新的定时任务。
Click to show internal directories.
Click to hide internal directories.