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() if the.CronStr != "" { log.Printf("cronStr=%s", the.CronStr) } } // RegisterTask 注册定时器方法 func (the *MonitorHelper) registerTask(cron string, task func()) { entryID, err := the.Cron.AddFunc(cron, task) if err != nil { log.Printf("cron 定时任务[%v]添加异常:%s", entryID, err.Error()) } } func (the *MonitorHelper) monitorStart() { the.Cron.Start() }