index_queue.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package services
  2. import (
  3. "context"
  4. "fmt"
  5. "hongze/mysteel_watch/global"
  6. "strings"
  7. "time"
  8. )
  9. // the service for log
  10. func AutoRefresh() {
  11. sub := global.Redis.Subscribe(context.TODO(), "autoRefresh")
  12. defer func() {
  13. sub.Close()
  14. if err := recover(); err != nil {
  15. fmt.Println("[AutoRefresh]", err)
  16. }
  17. }()
  18. i := 0
  19. for {
  20. i++
  21. fmt.Println(i)
  22. msg, err := sub.ReceiveMessage(context.TODO())
  23. if err != nil {
  24. fmt.Println("sub err:" + err.Error())
  25. }
  26. IndexHandle(msg.Payload)
  27. //global.Rc.Brpop(utils.REFRESH_INDEX, func(b []byte) {
  28. // filePath := string(b)
  29. // fmt.Println("filePath:", filePath)
  30. // IndexHandle(filePath)
  31. //})
  32. }
  33. }
  34. func IndexHandle(filePath string) {
  35. //err := UpdateComment(filePath)
  36. //if err != nil {
  37. // go alarm_msg.SendAlarmMsg(utils.APPNAME+" 指标数据未生成检测失败:"+err.Error()+";file:"+filePath, 3)
  38. //}
  39. filePath = strings.Replace(filePath, `"`, ``, -1)
  40. fmt.Println("开始刷新文件:", filePath)
  41. time.Sleep(1 * time.Second)
  42. MysteelChemicalRefresh(filePath)
  43. //刷新完成后,清除缓存
  44. global.Rc.Delete(filePath)
  45. }