Documentation
¶
Overview ¶
Package cron 提供 Cron 表达式解析和调度功能。
支持标准 5 字段 Cron 表达式:分 时 日 月 周
⚠️ 与标准 cron 的方言差异([#186]):dow 支持 7≡Sunday;不支持 MON/JAN 名字、不支持 L/W/# 扩展;不可满足表达式(2 月 31 日)Next 返回零值 time.Time 而非报错——从系统 crontab 迁移时注意。
Index ¶
- func NextSchedule(s Schedule, from time.Time, n int) []time.Time
- func RoundDuration(d time.Duration, precision time.Duration) time.Duration
- func SortEntries(entries []Entry)
- type ConstantDelaySchedule
- type DelaySchedule
- type Entry
- type RandomDelaySchedule
- type Schedule
- type SpecSchedule
- type WrapSchedule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NextSchedule ¶
NextSchedule 返回最近的 N 个调度时间。
n <= 0 返回空切片(不做任何调度计算)——负数此前会传给 make([]time.Time, 0, n) 直接 panic(makeslice: cap out of range)。
func RoundDuration ¶
RoundDuration 将时间向上取整到指定间隔。
Types ¶
type ConstantDelaySchedule ¶
ConstantDelaySchedule 以固定时间间隔调度。
func Every ¶
func Every(duration time.Duration) ConstantDelaySchedule
Every 返回一个以固定间隔调度的 Schedule。
⚠️ 语义三件套([#184](https://github.com/oekit/pkg/issues/184),此前零声明):
- duration < 1s **静默钳到 1s**(本调度器秒级粒度,ConstantDelaySchedule 沿用 robfig 形态)——配 Every(500ms) 期望半秒节奏会得到 1s,调度密度 减半无任何信号;
- 亚秒部分**截断**(1500ms ⇒ 1s);
- Next 按传入时间的秒对齐,实际触发间隔 = delay 但不保证与「上次执行 完成」挂钩(固定时刻表,非完成后间隔;后者用 oekit/concurrency/loop 的 IntervalAfterCompletion)。
需要亚秒级高频节奏不该用 cron——直接 go-timer/loop。
type DelaySchedule ¶
DelaySchedule 在固定延迟后触发。
func NewDelaySchedule ¶
func NewDelaySchedule(delay time.Duration) DelaySchedule
NewDelaySchedule 创建一个延迟调度器。
type RandomDelaySchedule ¶
RandomDelaySchedule 在随机延迟后触发。
func NewRandomDelaySchedule ¶
func NewRandomDelaySchedule(min, max time.Duration) RandomDelaySchedule
NewRandomDelaySchedule 创建一个随机延迟调度器。
type SpecSchedule ¶
SpecSchedule 根据 cron 表达式调度任务。