Ai
2 Star 1 Fork 2

go-mao/mao

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
crontab_domain.go 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
package frame
import (
"time"
"gitee.com/go-mao/mao/libs/crontab"
"gitee.com/go-mao/mao/libs/try"
)
type crontabDomain struct {
cronTask *crontab.CronSchduler
server *Server
}
// 初始化定时任务
func (this *crontabDomain) init(module ModuleInterface) {
if this.cronTask == nil {
this.cronTask = crontab.New()
}
taskList := module.Crontabs()
for _, task := range taskList {
taskClone := task
call := func() {
tl := this.server.TaskLine()
try.Do(func() {
this.server.logger.Debugf("[CRON] %s [%d] %s", time.Now().Format("2006-01-02 15:04:05"), tl.index, taskClone.Name())
taskClone.Handler(tl)
}, func(e try.Exception) {
this.server.logger.Errorf("[CRON] %s [%d] [%s] [%d] %s", time.Now().Format("2006-01-02 15:04:05"), tl.index, taskClone.Name(), e.ErrCode(), e.ErrMsg())
})
}
job, err := crontab.NewJobModel(taskClone.Schedule(), call)
if err != nil {
try.Throw(CODE_FATAL, "定时任务【"+taskClone.Name()+"】错误:", err.Error())
}
this.cronTask.DynamicRegister(taskClone.Name(), job)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/go-mao/mao.git
git@gitee.com:go-mao/mao.git
go-mao
mao
mao
v1.0.25

搜索帮助