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

cron

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTools

func GetTools(service *cronPkg.CronService, opts ...CronOption) []tool.BaseTool

GetTools 从已有的 CronService 获取定时任务工具列表

Types

type CronOption

type CronOption func(*CronTool)

CronOption 配置选项

func WithOnJobProcessed added in v0.3.3

func WithOnJobProcessed(fn func(job *cronPkg.CronJob, response string, err error)) CronOption

WithOnJobProcessed 设置任务处理完成后的回调(观测用)。 该回调只在独立使用本工具(未配合 cronPkg.NewCronAgent)时不会被自动触发; 配合 NewCronAgent 时请使用 cronPkg.WithOnJobProcessed。

func WithOnJobTriggered

func WithOnJobTriggered(fn func(job *cronPkg.CronJob)) CronOption

WithOnJobTriggered 设置任务触发时的回调(观测用,不拦截模型处理)。 注意:如果同时使用 cronPkg.NewCronAgent,Agent 会安装自己的任务处理器, 该回调会被合并进 Agent 的处理器中执行。

type CronParams

type CronParams struct {
	// 操作类型
	Action string `json:"action" jsonschema:"description=操作类型,required,enum=add,enum=list,enum=remove,enum=enable,enum=disable"`

	// 定时任务的消息内容(add 时必填)
	Message string `json:"message,omitempty" jsonschema:"description=定时任务触发时的消息内容"`

	// 一次性定时:从现在开始的秒数后触发(如 600 表示 10 分钟后)
	AtSeconds *int64 `json:"at_seconds,omitempty" jsonschema:"description=一次性定时:从现在开始多少秒后触发"`

	// 周期定时:每隔多少秒触发一次(如 3600 表示每小时)
	EverySeconds *int64 `json:"every_seconds,omitempty" jsonschema:"description=周期定时:每隔多少秒触发一次"`

	// Cron 表达式(如 '0 9 * * *' 表示每天早上 9 点)
	CronExpr string `json:"cron_expr,omitempty" jsonschema:"description=Cron 表达式,用于复杂的周期调度"`

	// 任务 ID(remove/enable/disable 时必填)
	JobID string `json:"job_id,omitempty" jsonschema:"description=任务 ID(用于 remove/enable/disable 操作)"`
}

CronParams 工具参数

type CronTool

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

CronTool 定时任务工具

Jump to

Keyboard shortcuts

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