You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
542 B
29 lines
542 B
2 weeks ago
|
package monitors
|
||
|
|
||
|
import (
|
||
|
"github.com/robfig/cron/v3"
|
||
|
"log"
|
||
|
)
|
||
|
|
||
|
type MonitorHelper struct {
|
||
|
CronStr string
|
||
|
Cron *cron.Cron
|
||
|
}
|
||
|
|
||
|
func (the *MonitorHelper) initial() {
|
||
|
the.Cron = cron.New()
|
||
|
log.Printf("cronStr=%s", the.CronStr)
|
||
|
}
|
||
|
|
||
|
// RegisterFun 注册定时器方法
|
||
|
func (the *MonitorHelper) registerFun(task func()) {
|
||
|
entryID, err := the.Cron.AddFunc(the.CronStr, task)
|
||
|
if err != nil {
|
||
|
log.Printf("cron 定时任务[%v]添加异常:%s", entryID, err.Error())
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (the *MonitorHelper) monitorStart() {
|
||
|
the.Cron.Start()
|
||
|
}
|