infoc.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package service
  2. import (
  3. "go-common/library/log"
  4. binfoc "go-common/library/log/infoc"
  5. "go-common/library/stat/prom"
  6. )
  7. // 用户阅读专栏时长上报
  8. type readInfo struct {
  9. aid int64
  10. mid int64
  11. buvid string
  12. ip string
  13. duration int64
  14. from string
  15. }
  16. // ReadInfoc .
  17. func (s *Service) ReadInfoc(aid int64, mid int64, buvid string, ip string, duration int64, from string) {
  18. s.infoc(readInfo{
  19. aid: aid,
  20. mid: mid,
  21. buvid: buvid,
  22. ip: ip,
  23. duration: duration,
  24. from: from,
  25. })
  26. }
  27. func (s *Service) infoc(i interface{}) {
  28. select {
  29. case s.logCh <- i:
  30. default:
  31. log.Warn("infocproc chan full")
  32. }
  33. }
  34. // writeInfoc
  35. func (s *Service) infocproc() {
  36. var (
  37. readInfoc = binfoc.New(s.c.ReadInfoc)
  38. )
  39. for {
  40. i, ok := <-s.logCh
  41. if !ok {
  42. log.Warn("infoc proc exit")
  43. return
  44. }
  45. prom.BusinessInfoCount.State("infoc_channel", int64(len(s.logCh)))
  46. switch l := i.(type) {
  47. case readInfo:
  48. readInfoc.Info(l.aid, l.mid, l.buvid, l.ip, l.duration, l.from)
  49. log.Info("infocproc readInfoc param(%+v)", l)
  50. }
  51. }
  52. }