1 Star 1 Fork 1

YashanDB Community/cron

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cron_task.go 837 Bytes
一键复制 编辑 原始数据 按行查看 历史
yangdeliu 提交于 2025-01-02 16:19 +08:00 . make simplify
package yascron
import (
"time"
)
type TaskId int
type CronTask struct {
id TaskId
name string
timeExpression string
schedule Schedule
next time.Time
prev time.Time
job Job
}
func NewCronTask(name, timeExpression string, f func()) *CronTask {
t := &CronTask{
name: name,
timeExpression: timeExpression,
job: FuncJob(f),
}
return t
}
func (c *CronTask) NextExecTime() time.Time {
return c.schedule.Next(time.Now())
}
// implement sort.Sort
type byTime []*CronTask
func (s byTime) Len() int { return len(s) }
func (s byTime) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s byTime) Less(i, j int) bool {
if s[i].next.IsZero() {
return false
}
if s[j].next.IsZero() {
return true
}
return s[i].next.Before(s[j].next)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yashan_tech/cron.git
git@gitee.com:yashan_tech/cron.git
yashan_tech
cron
cron
yasdb-3.0.2

搜索帮助