del_video.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package ugc
  2. import (
  3. appDao "go-common/app/job/main/tv/dao/app"
  4. "go-common/app/job/main/tv/dao/lic"
  5. "go-common/library/database/sql"
  6. "go-common/library/log"
  7. "time"
  8. )
  9. func (s *Service) delVideoproc() {
  10. defer s.waiter.Done()
  11. for {
  12. if s.daoClosed {
  13. log.Info("delVideoproc DB closed!")
  14. return
  15. }
  16. // pick deleted videos
  17. videoIDs, err := s.dao.DeletedVideos(ctx)
  18. if err != nil && err != sql.ErrNoRows {
  19. log.Error("videoIDs Error %v", err)
  20. appDao.PromError("SyncDelVid:Err")
  21. time.Sleep(time.Duration(s.c.UgcSync.Frequency.SyncFre))
  22. continue
  23. }
  24. if err == sql.ErrNoRows || len(videoIDs) == 0 {
  25. log.Info("No SyncDelVid Data to Sync")
  26. time.Sleep(time.Duration(s.c.UgcSync.Frequency.SyncFre))
  27. continue
  28. }
  29. if err = s.delVideoLic(videoIDs); err != nil {
  30. appDao.PromError("SyncDelVid:Err")
  31. log.Error("delLic error %v, cids %s", err, videoIDs)
  32. time.Sleep(time.Duration(s.c.UgcSync.Frequency.SyncFre))
  33. continue
  34. }
  35. appDao.PromInfo("SyncDelVid:Succ")
  36. }
  37. }
  38. // delVideoErr: it logs the error and postpone the videos for the next submit
  39. func (s *Service) delVideoErr(cids []int, fmt string, err error) {
  40. s.dao.PpDelVideos(ctx, cids)
  41. log.Error(fmt, cids, err)
  42. }
  43. // delVideoLic: sync our deleted video data to License owner
  44. func (s *Service) delVideoLic(videoIDs []int) (err error) {
  45. var (
  46. xmlBody string
  47. sign = s.c.Sync.Sign
  48. prefix = s.c.Sync.UGCPrefix
  49. )
  50. xmlBody = lic.DelEpLic(prefix, sign, videoIDs)
  51. // call api
  52. if _, err = s.licDao.CallRetry(ctx, s.c.Sync.API.DelEPURL, xmlBody); err != nil {
  53. s.delVideoErr(videoIDs, "xml call %v error %v", err)
  54. return
  55. }
  56. // update the videos' submit status to finish
  57. if err = s.dao.FinishDelVideos(ctx, videoIDs); err != nil {
  58. log.Info("Del Video Finish, Sync For Vids: %v", videoIDs)
  59. s.delVideoErr(videoIDs, "FinishDelVideos %v error %v", err)
  60. }
  61. return
  62. }