task.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. //每5分钟检测一次,指标生成
  12. //_, err := c.AddFunc("0 */1 * * * *", CheckIndexCreate)
  13. //if err != nil {
  14. // global.LOG.Info("DownloadCvTask err" + err.Error())
  15. //}
  16. //////每30分钟检测一次,周度指标刷新
  17. ////_, err = c.AddFunc("0 */30 * * * *", services.IndexRefreshWeek)
  18. ////if err != nil {
  19. //// global.LOG.Info("DownloadCvTask err" + err.Error())
  20. //// panic("DownloadCvTask err" + err.Error())
  21. ////}
  22. //
  23. // 每天下午5点开始刷新excel表格
  24. _, err := c.AddFunc("0 0 17 * * *", services.RefreshExcel)
  25. //_, err := c.AddFunc("0 01 15 * * *", services.RefreshExcel)
  26. if err != nil {
  27. global.LOG.Info("RefreshExcel err" + err.Error())
  28. }
  29. c.Start()
  30. //
  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. //}