gf
gf copied to clipboard
gron的表达式解析和定时器功能分离
type Schedule interface {
// Next returns the next activation time, later than the given time.
// Next is invoked initially, and then each time the job is run.
Next(time.Time) time.Time
}
type SpecSchedule struct {
Second, Minute, Hour, Dom, Month, Dow uint64
// Override location for this schedule.
Location *time.Location
}
表达式解析出来的是SpecSchedule (实现了Schedule ) 对于定时器来说,只要实现 Next(time.Time) time.Time 方法就行,没有耦合
详细可参考 github.com/robfig/cron/v3
@15951836388 能描述一下你的业务场景吗?
我只是想用cron的表达式解析而已,并不需要用定时任务系统。 而且出于解耦的方面考虑,也不该把2个功能关联死吧
大佬,有分离的计划吗?我只要用表达式解析这个功能
@15951836388 你提的建议不错,不过不是最优先的工作计划,感兴趣的话可以提PR,或者等待其他小伙伴贡献吧。