task.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package init_serve
  2. import (
  3. "github.com/robfig/cron/v3"
  4. "hongze/hongtao3_watch/global"
  5. "hongze/hongtao3_watch/services"
  6. "hongze/hongtao3_watch/watch"
  7. )
  8. func InitTask() {
  9. //services.RefreshExcel()
  10. c := cron.New(cron.WithSeconds())
  11. // 定时统一更新(日度、周度指标)
  12. if global.CONFIG.Serve.RefreshTime == "" {
  13. //panic("未配置数据统一刷新时间")
  14. // 未配置时间的话,那么默认每天17点更新一次
  15. global.CONFIG.Serve.RefreshTime = "0 0 17 * * *"
  16. }
  17. //fmt.Println(global.CONFIG.Serve.RefreshTime)
  18. // 每天下午5点开始刷新excel表格
  19. _, err := c.AddFunc(global.CONFIG.Serve.RefreshTime, services.RefreshExcel)
  20. //_, err := c.AddFunc("0 55 13 * * *", services.RefreshExcel)
  21. if err != nil {
  22. global.LOG.Info("RefreshExcel err" + err.Error())
  23. }
  24. //每2分钟检测一次指标文件是否更新
  25. _, err = c.AddFunc("0 */1 * * * *", watch.ReadWatchIndexFile)
  26. //_, err = c.AddFunc("*/30 * * * * *", watch.ReadWatchIndexFile)
  27. if err != nil {
  28. global.LOG.Info("watch.ReadWatchIndexFile err" + err.Error())
  29. }
  30. c.Start()
  31. // 监听文件
  32. //go watch.ListenFolderNew()
  33. // 处理excel
  34. go services.HandleFileUpdate()
  35. // 处理调用刷新excel的服务(调用python)
  36. go services.HandleRefreshExcel()
  37. ////redis 队列刷新指标
  38. //go services.AutoRefresh()
  39. //CheckIndexCreate()
  40. //services.Merge()
  41. //yearFile="year.xlsx"
  42. //filePath := utils.IndexMsergeSaveDir + "season.xlsx"
  43. //services.DataAnalysis(filePath)
  44. //services.Merge()
  45. }
  46. //检测指标数据是否生成
  47. //func CheckIndexCreate() {
  48. // var err error
  49. // defer func() {
  50. // if err != nil && err.Error() != "record not found" {
  51. // global.LOG.Info(utils.APPNAME + " 定时任务 出错" + time.Now().Format("2006-01-02 15:04:05") + ";Err:" + err.Error())
  52. // go alarm_msg.SendAlarmMsg(utils.APPNAME+" 定时任务 出错"+time.Now().Format("2006-01-02 15:04:05")+";Err:"+err.Error(), 3)
  53. // }
  54. // }()
  55. // err = services.IndexCreateCheck()
  56. //}