mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-04 00:10:25 +08:00
fix: 定时任务问题修复
This commit is contained in:
37
server/pkg/scheduler/scheduler.go
Normal file
37
server/pkg/scheduler/scheduler.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user