recommend.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/job/main/mcn/model"
  5. "go-common/library/log"
  6. "github.com/pkg/errors"
  7. )
  8. // McnRecommendCron .
  9. func (s *Service) McnRecommendCron() {
  10. defer func() {
  11. if r := recover(); r != nil {
  12. r = errors.WithStack(r.(error))
  13. log.Error("recover panic error(%+v)", r)
  14. }
  15. }()
  16. var (
  17. err error
  18. limit = 100
  19. c = context.TODO()
  20. rps []*model.McnUpRecommendPool
  21. )
  22. for {
  23. if rps, err = s.dao.McnUpRecommendSources(c, limit); err != nil {
  24. log.Error("s.dao.McnUpRecommendSources(%d) error(%+v)", limit, err)
  25. return
  26. }
  27. if len(rps) == 0 {
  28. log.Warn("big data recommend up data is empty!")
  29. return
  30. }
  31. for _, v := range rps {
  32. rp := new(model.McnUpRecommendPool)
  33. *rp = *v
  34. rp.GenerateTime = v.Mtime
  35. if _, err = s.dao.AddMcnUpRecommend(c, rp); err != nil {
  36. log.Error("s.dao.AddMcnUpRecommend(%+v) error(%+v)", rp, err)
  37. continue
  38. }
  39. if _, err = s.dao.DelMcnUpRecommendSource(c, v.ID); err != nil {
  40. log.Error("s.dao.DelMcnUpRecommendSource(%d) error(%+v)", v.ID, err)
  41. continue
  42. }
  43. log.Info("source id(%d) sync to recommend poll(%+v)", v.ID, rp)
  44. }
  45. }
  46. }
  47. // DealFailRecommendCron .
  48. func (s *Service) DealFailRecommendCron() {
  49. defer func() {
  50. if r := recover(); r != nil {
  51. r = errors.WithStack(r.(error))
  52. log.Error("recover panic error(%+v)", r)
  53. }
  54. }()
  55. var (
  56. err error
  57. c = context.TODO()
  58. )
  59. if _, err = s.dao.DelMcnUpRecommendPool(c); err != nil {
  60. log.Error("s.dao.DelMcnUpRecommendPool error(%+v)", err)
  61. }
  62. }