sync_arc.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package ugc
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/job/main/tv/dao/lic"
  6. model "go-common/app/job/main/tv/model/pgc"
  7. ugcmdl "go-common/app/job/main/tv/model/ugc"
  8. "go-common/library/log"
  9. )
  10. // syncLic: sync our arc data to License owner
  11. func (s *Service) modArcproc() (err error) {
  12. defer s.waiter.Done()
  13. var cid int64
  14. for {
  15. cAids, ok := <-s.modArcCh
  16. if !ok {
  17. log.Warn("[modLic] channel quit")
  18. return
  19. }
  20. for _, cAid := range cAids {
  21. if cid, err = s.dao.VideoSubmit(ctx, cAid); err != nil {
  22. log.Warn("modArc Aid %d, Err %v, Jump", cAid, err)
  23. time.Sleep(time.Duration(s.c.UgcSync.Frequency.ErrorWait))
  24. continue
  25. }
  26. log.Info("modArc Aid %d, Can submit because CID %d already submitted", cAid, cid)
  27. if err = s.modArc(ctx, cAid); err != nil {
  28. log.Warn("modArc Aid %d Err %v", cAid, err)
  29. continue
  30. }
  31. }
  32. }
  33. }
  34. func (s *Service) modArc(ctx context.Context, cAid int64) (err error) {
  35. var (
  36. skeleton = &ugcmdl.LicSke{}
  37. licData *model.License
  38. xmlBody string
  39. arc *ugcmdl.Archive
  40. )
  41. if arc, err = s.dao.ParseArc(ctx, cAid); err != nil {
  42. log.Warn("ParseArc Aid %d not found", cAid)
  43. }
  44. skeleton.Arc = arc.ToSimple()
  45. skeleton.Videos = []*ugcmdl.SimpleVideo{} // empty videos
  46. // build the license data and transform to xml
  47. if licData, err = s.auditMsg(skeleton); err != nil {
  48. log.Error("build lic msg %d error %v", cAid, err)
  49. return
  50. }
  51. xmlBody = lic.PrepareXML(licData)
  52. // call api
  53. if _, err = s.licDao.CallRetry(ctx, s.c.Sync.API.AddURL, xmlBody); err != nil {
  54. log.Error("xml call %d error %v", cAid, err)
  55. return
  56. }
  57. // update the arc & videos' submit status to finish
  58. if err = s.dao.FinishArc(ctx, cAid); err != nil {
  59. log.Error("finishArc %d Error %v", cAid, err)
  60. }
  61. return
  62. }
  63. // wrapSyncLic warps the syncLic method with aidMap
  64. func (s *Service) wrapSyncLic(ctx context.Context, aids []int64) (err error) {
  65. var arc *ugcmdl.Archive
  66. for _, cAid := range aids {
  67. if arc, err = s.dao.ParseArc(ctx, cAid); err != nil {
  68. log.Warn("wrapSyncLic ParseArc Aid %d not found", cAid)
  69. continue
  70. }
  71. arcAllow := &ugcmdl.ArcAllow{}
  72. arcAllow.FromArchive(arc)
  73. if !s.arcAllowImport(arcAllow) {
  74. log.Warn("wrapSyncLic cAid %d Can't play", cAid)
  75. continue
  76. }
  77. if arc.Deleted == 1 {
  78. log.Warn("wrapSyncLic cAid %d Deleted", cAid)
  79. continue
  80. }
  81. if err = s.syncLic(cAid, arc.ToSimple()); err != nil {
  82. log.Error("wrapSyncLic cAid %d Err %v", cAid, err)
  83. continue
  84. }
  85. }
  86. return
  87. }