del_arc.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package ugc
  2. import (
  3. "time"
  4. appDao "go-common/app/job/main/tv/dao/app"
  5. "go-common/app/job/main/tv/dao/lic"
  6. "go-common/library/database/sql"
  7. "go-common/library/log"
  8. )
  9. func (s *Service) delArcproc() {
  10. defer s.waiter.Done()
  11. for {
  12. if s.daoClosed {
  13. log.Info("delArcproc DB closed!")
  14. return
  15. }
  16. // build the skeleton, arc + video data
  17. cAid, err := s.dao.DeletedArc(ctx)
  18. if err != nil && err != sql.ErrNoRows {
  19. log.Error("DeletedArc Error %v", err)
  20. appDao.PromError("SyncDelAid:Err")
  21. time.Sleep(time.Duration(s.c.UgcSync.Frequency.SyncFre))
  22. continue
  23. }
  24. if err == sql.ErrNoRows || cAid == 0 {
  25. log.Info("SyncDelAid No Data to Sync")
  26. time.Sleep(time.Duration(s.c.UgcSync.Frequency.SyncFre))
  27. continue
  28. }
  29. if err = s.delLic(cAid); err != nil {
  30. appDao.PromError("SyncDelAid:Err")
  31. log.Error("delLic error %v, aid %d", err, cAid)
  32. time.Sleep(time.Duration(s.c.UgcSync.Frequency.SyncFre))
  33. continue
  34. }
  35. appDao.PromInfo("SyncDelAid:Succ")
  36. }
  37. }
  38. // delArcErr: it logs the error and postpone the videos for the next submit
  39. func (s *Service) delArcErr(aid int64, fmt string, err error) {
  40. s.dao.PpDelArc(ctx, aid)
  41. log.Error(fmt, aid, err)
  42. }
  43. // delLic: sync our arc data to License owner
  44. func (s *Service) delLic(cAid int64) (err error) {
  45. var (
  46. xmlBody string
  47. sign = s.c.Sync.Sign
  48. prefix = s.c.Sync.UGCPrefix
  49. )
  50. xmlBody = lic.PrepareXML(lic.DelLic(sign, prefix, cAid))
  51. // call api
  52. if _, err = s.licDao.CallRetry(ctx, s.c.Sync.API.DelSeasonURL, xmlBody); err != nil {
  53. s.delArcErr(cAid, "xml call %d error %v", err)
  54. return
  55. }
  56. // update the arc & videos' submit status to finish
  57. if err = s.dao.FinishDelArc(ctx, cAid); err != nil {
  58. s.delArcErr(cAid, "FinishDelArc %d error %v", err)
  59. }
  60. return
  61. }
  62. func (s *Service) delArc(aid int64) (err error) {
  63. var tx *sql.Tx
  64. // check whether the arc exist in our DB
  65. if !s.arcExist(aid) {
  66. log.Warn("Del Arc %d, it doesn't exist", aid)
  67. return
  68. }
  69. // delete the arc, put submit to 1
  70. if tx, err = s.dao.BeginTran(ctx); err != nil { // begin transaction
  71. return
  72. }
  73. if err = s.dao.TxDelArc(tx, aid); err != nil {
  74. appDao.PromError("DelArc:Err")
  75. tx.Rollback()
  76. return
  77. }
  78. // delete the videos put submit to 1
  79. if err = s.dao.TxDelVideos(tx, aid); err != nil {
  80. appDao.PromError("DelArc:Err")
  81. tx.Rollback()
  82. return
  83. }
  84. appDao.PromInfo("DelArc:Succ")
  85. tx.Commit()
  86. return
  87. }