task.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package init_serve
  2. import (
  3. "github.com/robfig/cron/v3"
  4. "hongze/hrms_api/global"
  5. "hongze/hrms_api/services/alarm_msg"
  6. rcrtService "hongze/hrms_api/services/rcrt"
  7. "hongze/hrms_api/utils"
  8. "time"
  9. )
  10. func InitTask() {
  11. if global.CONFIG.Serve.RunMode != "debug" {
  12. if utils.GetInterfaceAddrs() != "172.19.173.232" {
  13. return
  14. }
  15. }else{
  16. //return
  17. }
  18. c := cron.New(cron.WithSeconds())
  19. _, err := c.AddFunc("0 */5 * * * *", DownloadCvTask)
  20. if err != nil {
  21. global.LOG.Info("DownloadCvTask err"+err.Error())
  22. panic("DownloadCvTask err"+err.Error())
  23. }
  24. c.Start()
  25. }
  26. func DownloadCvTask() {
  27. global.LOG.Info("DownloadCvTask start")
  28. var err error
  29. var errMsg string
  30. defer func() {
  31. if err != nil{
  32. global.LOG.Info(utils.APPNAME+" 定时任务 出错"+time.Now().Format(utils.FormatDateTime)+";Err:"+errMsg+" "+err.Error())
  33. go alarm_msg.SendAlarmMsg(utils.APPNAME+" 定时任务 出错"+time.Now().Format(utils.FormatDateTime)+";Err:"+errMsg+" "+err.Error(), 3)
  34. }
  35. }()
  36. err, errMsg = rcrtService.DownloadCv()
  37. global.LOG.Info("DownloadCvTask end")
  38. return
  39. }