read.go 1013 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/library/log"
  6. )
  7. func (s *Service) checkReadStatus() {
  8. for {
  9. var c = context.TODO()
  10. readSet, err := s.dao.ReadPingSet(c)
  11. if err != nil || len(readSet) == 0 {
  12. time.Sleep(5 * time.Second)
  13. continue
  14. }
  15. now := time.Now().Unix()
  16. for _, read := range readSet {
  17. last, err := s.dao.ReadPing(c, read.Buvid, read.Aid)
  18. if err != nil {
  19. time.Sleep(time.Second)
  20. continue
  21. }
  22. if now-last < 30 {
  23. continue
  24. }
  25. if err = s.dao.DelReadPingSet(c, read); err != nil {
  26. time.Sleep(time.Second)
  27. continue
  28. }
  29. if last == 0 {
  30. log.Error("阅读心跳没取到:buvid(%s) aid(%d)", read.Buvid, read.Aid)
  31. continue
  32. }
  33. read.EndTime = last
  34. log.Info("上传用户阅读记录至数据中心: %+v", read)
  35. s.ReadInfoc(read.Aid, read.Mid, read.Buvid, read.IP, read.EndTime-read.StartTime, read.From)
  36. }
  37. return
  38. }
  39. }
  40. func (s *Service) checkReadStatusProc() {
  41. for {
  42. s.checkReadStatus()
  43. time.Sleep(time.Minute)
  44. }
  45. }