rebuild.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. rebuild: user portrait score reset to normal if it's score large than punishment threshold score
  3. */
  4. package service
  5. import (
  6. "context"
  7. "time"
  8. spy "go-common/app/service/main/spy/model"
  9. "go-common/library/log"
  10. )
  11. const (
  12. _normal = 0
  13. _ps = 100
  14. )
  15. func (s *Service) reBuild() {
  16. var (
  17. err error
  18. count int64
  19. )
  20. current := time.Now()
  21. before30d, _ := time.ParseDuration("-720h")
  22. before31d, _ := time.ParseDuration("-744h")
  23. start := current.Add(before31d)
  24. end := current.Add(before30d)
  25. log.Info("ReBuild task start: start:(%s) end:(%s))", start, end)
  26. for t := 0; t < int(s.c.Property.UserInfoShard); t++ {
  27. if count, err = s.dao.ReBuildMidCount(context.TODO(), t, _normal, start, end); err != nil {
  28. log.Error("s.dao.ReBuildMidCount(%s, %s), err(%v)", start, end, err)
  29. continue
  30. }
  31. log.Info("ReBuild task: index:%d, count:%d)", t, count)
  32. if count <= 0 {
  33. continue
  34. }
  35. total := count / _ps
  36. log.Info("ReBuild task: shard:%d, count:%d, total:%d)", t, count, total)
  37. for i := 0; int64(i) <= total; i++ {
  38. midList, err := s.dao.ReBuildMidList(context.TODO(), t, _normal, start, end, _ps)
  39. if err != nil {
  40. log.Error("s.dao.ReBuildMidList(%s, %s, %d, %d)", start, end, i, _ps)
  41. continue
  42. }
  43. for _, mid := range midList {
  44. if err := s.spyRPC.ReBuildPortrait(context.TODO(), &spy.ArgReBuild{Mid: mid, Reason: "自动恢复行为得分"}); err != nil {
  45. log.Error("s.spyRPC.ReBuildPortrait(%d), err:%v", mid, err)
  46. continue
  47. }
  48. log.Info("ReBuild task: mid(%d) ReBuild Portrait success)", mid)
  49. }
  50. }
  51. }
  52. log.Info("ReBuild task end: start:(%s) end:(%s))", start, end)
  53. }