package init_serve import ( "github.com/robfig/cron/v3" "hongze/hrms_api/global" "hongze/hrms_api/services/alarm_msg" rcrtService "hongze/hrms_api/services/rcrt" "hongze/hrms_api/utils" "time" ) func InitTask() { if global.CONFIG.Serve.RunMode != "debug" { if utils.GetInterfaceAddrs() != "172.19.173.232" { return } }else{ //return } c := cron.New(cron.WithSeconds()) _, err := c.AddFunc("0 */5 * * * *", DownloadCvTask) if err != nil { global.LOG.Info("DownloadCvTask err"+err.Error()) panic("DownloadCvTask err"+err.Error()) } c.Start() } func DownloadCvTask() { global.LOG.Info("DownloadCvTask start") var err error var errMsg string defer func() { if err != nil{ global.LOG.Info(utils.APPNAME+" 定时任务 出错"+time.Now().Format(utils.FormatDateTime)+";Err:"+errMsg+" "+err.Error()) go alarm_msg.SendAlarmMsg(utils.APPNAME+" 定时任务 出错"+time.Now().Format(utils.FormatDateTime)+";Err:"+errMsg+" "+err.Error(), 3) } }() err, errMsg = rcrtService.DownloadCv() global.LOG.Info("DownloadCvTask end") return }