del_season.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package pgc
  2. import (
  3. "database/sql"
  4. "time"
  5. "go-common/app/job/main/tv/dao/lic"
  6. "go-common/library/log"
  7. )
  8. // sync the deleted season data to the license owner
  9. func (s *Service) delSeason() {
  10. var (
  11. sign = s.c.Sync.Sign
  12. prefix = s.c.Sync.AuditPrefix
  13. )
  14. defer s.waiter.Done()
  15. for {
  16. if s.daoClosed {
  17. log.Info("delSeason DB closed!")
  18. return
  19. }
  20. delSeason, err := s.dao.DelSeason(ctx)
  21. if err == sql.ErrNoRows || len(delSeason) == 0 {
  22. log.Info("No deleted data to pick from Season to sync")
  23. time.Sleep(time.Duration(s.c.Sync.Frequency.FreModSeason))
  24. continue
  25. }
  26. for _, v := range delSeason {
  27. data := lic.DelLic(sign, prefix, v.ID)
  28. // ignore the program part during modified season sync
  29. body := lic.PrepareXML(data)
  30. res, err := s.licDao.CallRetry(ctx, s.c.Sync.API.DelSeasonURL, body)
  31. // 3 times still error
  32. if err != nil {
  33. log.Error("DelSeasonURL interface not available!Sid: %v, Err: %v", v.ID, err)
  34. s.dao.DelaySeason(ctx, v.ID)
  35. time.Sleep(time.Duration(s.c.Sync.Frequency.ErrorWait))
  36. // avoid always be stuck by one error data
  37. break
  38. }
  39. if err == nil && res != nil {
  40. _, err := s.dao.RejectSeason(ctx, int(v.ID))
  41. if err != nil {
  42. log.Error("DelSeasonSync season %v to rejected fail!", v.ID)
  43. // sync next one
  44. continue
  45. }
  46. }
  47. }
  48. // break after each loop
  49. time.Sleep(1 * time.Second)
  50. }
  51. }