del_arc.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package ugc
  2. import (
  3. "context"
  4. "go-common/library/log"
  5. "time"
  6. )
  7. const (
  8. _deletedArc = "SELECT aid FROM ugc_archive WHERE submit = 1 AND deleted = 1 AND retry < unix_timestamp(now()) LIMIT 1"
  9. _finishDelArc = "UPDATE ugc_archive SET submit = 0 WHERE aid = ? AND deleted = 1"
  10. _ppDelArc = "UPDATE ugc_archive SET retry = ? WHERE aid = ? AND deleted = 1"
  11. )
  12. // DeletedArc picks the deleted archive to sync
  13. func (d *Dao) DeletedArc(c context.Context) (aid int64, err error) {
  14. err = d.DB.QueryRow(c, _deletedArc).Scan(&aid)
  15. return
  16. }
  17. // FinishDelArc updates the submit status from 1 to 0
  18. func (d *Dao) FinishDelArc(c context.Context, aid int64) (err error) {
  19. if _, err = d.DB.Exec(c, _finishDelArc, aid); err != nil {
  20. log.Error("FinishVideos Error: %v", aid, err)
  21. }
  22. return
  23. }
  24. // PpDelArc postpones the archive's submit in 30 mins
  25. func (d *Dao) PpDelArc(c context.Context, aid int64) (err error) {
  26. var delay = time.Now().Unix() + int64(d.conf.UgcSync.Frequency.ErrorWait)
  27. if _, err = d.DB.Exec(c, _ppDelArc, delay, aid); err != nil {
  28. log.Error("PostponeArc, failed to delay: (%v,%v), Error: %v", delay, aid, err)
  29. }
  30. return
  31. }