fix: 定时任务问题修复

This commit is contained in:
meilin.huang
2022-07-24 15:37:13 +08:00
parent 76d6fc3ba5
commit 577802e5ad
5 changed files with 37 additions and 58 deletions

View File

@@ -0,0 +1,37 @@
package scheduler
import (
"mayfly-go/pkg/biz"
"github.com/robfig/cron/v3"
)
func init() {
Start()
}
var cronService = cron.New()
func Start() {
cronService.Start()
}
func Stop() {
cronService.Stop()
}
func Remove(id cron.EntryID) {
cronService.Remove(id)
}
func GetCron() *cron.Cron {
return cronService
}
func AddFun(spec string, cmd func()) cron.EntryID {
id, err := cronService.AddFunc(spec, cmd)
if err != nil {
panic(biz.NewBizErr("添加任务失败:" + err.Error()))
}
return id
}