Documentation
¶
Index ¶
- func Start()
- func Stop()
- type CronSchedule
- type DailySchedule
- type FullCronSchedule
- type IntervalSchedule
- type Schedule
- type Scheduler
- func (s *Scheduler) AddTask(name string, schedule Schedule, handler TaskHandler) *Task
- func (s *Scheduler) DisableTask(name string) error
- func (s *Scheduler) EnableTask(name string) error
- func (s *Scheduler) GetTask(name string) (*Task, error)
- func (s *Scheduler) ListTasks() []*Task
- func (s *Scheduler) RemoveTask(name string)
- func (s *Scheduler) RunTask(name string) error
- func (s *Scheduler) Start()
- func (s *Scheduler) Stop()
- type Task
- type TaskHandler
- type WeeklySchedule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CronSchedule ¶
type CronSchedule struct {
Minute string // 分钟: "*" 或具体值如 "0,15,30"
Hour string // 小时: "*" 或具体值如 "8,12"
}
CronSchedule 简化 Cron 调度(仅分钟和小时)
type DailySchedule ¶
DailySchedule 每日定时调度
type FullCronSchedule ¶
type FullCronSchedule struct {
Minute string // 分钟: 0-59, "*", "*/n", "a-b", "a,b,c"
Hour string // 小时: 0-23, "*", "*/n", "a-b", "a,b,c"
Day string // 日: 1-31, "*", "*/n", "a-b", "a,b,c"
Month string // 月: 1-12, "*", "*/n", "a-b", "a,b,c"
Weekday string // 星期: 0-6 (周日=0), "*", "*/n", "a-b", "a,b,c"
}
FullCronSchedule 完整 Cron 表达式调度 格式: "分钟 小时 日 月 星期" (5字段) 示例: "0 12 * * *" 每天12点
"0 0 1 * *" 每月1号凌晨 "0 9-17 * * 1-5" 周一到周五 9点到17点每小时
func ParseCron ¶
func ParseCron(expr string) *FullCronSchedule
ParseCron 解析完整 Cron 表达式 格式: "分钟 小时 日 月 星期" 示例:
"0 12 * * *" - 每天12:00 "*/15 * * * *" - 每15分钟 "0 9-17 * * 1-5" - 工作日9-17点每小时 "0 0 1 * *" - 每月1号凌晨 "0 0 * * 0" - 每周日凌晨
type IntervalSchedule ¶
IntervalSchedule 固定间隔调度
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler 调度器
type Task ¶
type Task struct {
Name string // 任务名称
Schedule Schedule // 调度规则
Handler TaskHandler // 任务处理函数
Enabled bool // 是否启用
LastRun time.Time // 上次运行时间
NextRun time.Time // 下次运行时间
RunCount int // 运行次数
}
Task 定时任务
type WeeklySchedule ¶
WeeklySchedule 每周定时调度
Click to show internal directories.
Click to hide internal directories.