index_queue.go 920 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package services
  2. import (
  3. "fmt"
  4. "hongze/mysteel_watch/global"
  5. "hongze/mysteel_watch/services/alarm_msg"
  6. "hongze/mysteel_watch/utils"
  7. "strings"
  8. "time"
  9. )
  10. // the service for log
  11. func AutoRefresh() {
  12. defer func() {
  13. if err := recover(); err != nil {
  14. fmt.Println("[AutoRefresh]", err)
  15. }
  16. }()
  17. for {
  18. global.Rc.Brpop(utils.REFRESH_INDEX, func(b []byte) {
  19. filePath := string(b)
  20. IndexHandle(filePath)
  21. })
  22. }
  23. }
  24. func IndexHandle(filePath string) {
  25. err := UpdateComment(filePath)
  26. if err != nil {
  27. go alarm_msg.SendAlarmMsg(utils.APPNAME+" 指标数据未生成检测失败:"+err.Error()+";file:"+filePath, 3)
  28. }
  29. time.Sleep(1 * time.Second)
  30. MysteelChemicalRefresh(filePath)
  31. indexCodeArr := strings.Split(filePath, "_")
  32. if len(indexCodeArr) > 1 {
  33. indexCode := indexCodeArr[0]
  34. key := utils.REFRESH_INDEX_CODE + indexCode
  35. if global.Re == nil && global.Rc != nil {
  36. global.Rc.Delete(key)
  37. }
  38. }
  39. }