task.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package init_serve
  2. import (
  3. "github.com/robfig/cron/v3"
  4. "hongze/mysteel_watch/services"
  5. "hongze/mysteel_watch/utils"
  6. "hongze/mysteel_watch/watch"
  7. "time"
  8. "hongze/mysteel_watch/global"
  9. "hongze/mysteel_watch/services/alarm_msg"
  10. )
  11. func InitTask() {
  12. c := cron.New(cron.WithSeconds())
  13. //每5分钟检测一次,指标生成
  14. _, err := c.AddFunc("0 */5 * * * *", CheckIndexCreate)
  15. if err != nil {
  16. global.LOG.Info("DownloadCvTask err" + err.Error())
  17. panic("DownloadCvTask err" + err.Error())
  18. }
  19. //每30分钟检测一次,指标生成
  20. _, err = c.AddFunc("0 */30 * * * *", services.IndexRefreshWeek)
  21. if err != nil {
  22. global.LOG.Info("DownloadCvTask err" + err.Error())
  23. panic("DownloadCvTask err" + err.Error())
  24. }
  25. //其他指标刷新
  26. _, err = c.AddFunc("0 00 03 * * *", services.IndexRefreshAll)
  27. if err != nil {
  28. global.LOG.Info("DownloadCvTask err" + err.Error())
  29. panic("DownloadCvTask err" + err.Error())
  30. }
  31. //其他指标刷新
  32. _, err = c.AddFunc("0 30 12 * * *", services.IndexRefreshAll)
  33. if err != nil {
  34. global.LOG.Info("DownloadCvTask err" + err.Error())
  35. panic("DownloadCvTask err" + err.Error())
  36. }
  37. c.Start()
  38. go watch.ListenFolderNew()
  39. }
  40. //检测指标数据是否生成
  41. func CheckIndexCreate() {
  42. var err error
  43. defer func() {
  44. if err != nil {
  45. global.LOG.Info(utils.APPNAME + " 定时任务 出错" + time.Now().Format("2006-01-02 15:04:05") + ";Err:" + err.Error())
  46. go alarm_msg.SendAlarmMsg(utils.APPNAME+" 定时任务 出错"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
  47. }
  48. }()
  49. err = services.IndexCreateCheck()
  50. }