del_cont.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package pgc
  2. import (
  3. "database/sql"
  4. "time"
  5. "go-common/app/job/main/tv/dao/lic"
  6. model "go-common/app/job/main/tv/model/pgc"
  7. "go-common/library/log"
  8. )
  9. // sync the deleted EP data to the license owner
  10. func (s *Service) delCont() {
  11. var (
  12. sign = s.c.Sync.Sign
  13. prefix = s.c.Sync.AuditPrefix
  14. )
  15. defer s.waiter.Done()
  16. for {
  17. if s.daoClosed {
  18. log.Info("delCont DB closed!")
  19. return
  20. }
  21. // pick data
  22. delCont, err := s.dao.DelCont(ctx)
  23. if err == sql.ErrNoRows || len(delCont) == 0 {
  24. log.Info("No deleted data to pick from Cont to sync")
  25. time.Sleep(time.Duration(s.c.Sync.Frequency.FreModSeason))
  26. continue
  27. }
  28. delEpids := []int{}
  29. for _, v := range delCont {
  30. delEpids = append(delEpids, v.EPID)
  31. }
  32. s.dao.DelaySync(ctx, delCont) // avoid always be stuck by one error data
  33. body := lic.DelEpLic(prefix, sign, delEpids)
  34. // call API
  35. var res *model.Document
  36. res, err = s.licDao.CallRetry(ctx, s.c.Sync.API.DelEPURL, body)
  37. // 3 times still error
  38. if err != nil {
  39. log.Error("DelEPURL interface not available! %v", err)
  40. time.Sleep(time.Duration(s.c.Sync.Frequency.ErrorWait))
  41. continue
  42. }
  43. // update the state
  44. if err == nil && res != nil {
  45. for _, v := range delCont {
  46. _, err := s.dao.SyncCont(ctx, v.EPID)
  47. if err != nil {
  48. log.Error("SyncCont EP %v to auditing fail!", v.ID)
  49. continue
  50. }
  51. }
  52. }
  53. // break after each loop
  54. time.Sleep(1 * time.Second)
  55. }
  56. }