del_video.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package ugc
  2. import (
  3. "context"
  4. "time"
  5. "go-common/library/database/sql"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _deletedVideos = "SELECT cid FROM ugc_video WHERE submit = 1 AND deleted = 1 AND retry < unix_timestamp(now()) LIMIT 5"
  10. _finishDelVideo = "UPDATE ugc_video SET submit = 0 WHERE cid = ? AND deleted = 1"
  11. _ppDelVideos = "UPDATE ugc_video SET retry = ? WHERE cid = ? AND deleted = 1"
  12. )
  13. // DeletedVideos picks the deleted videos to sync
  14. func (d *Dao) DeletedVideos(c context.Context) (delIds []int, err error) {
  15. var rows *sql.Rows
  16. if rows, err = d.DB.Query(c, _deletedVideos); err != nil { // get the qualified aid to sync
  17. return
  18. }
  19. defer rows.Close()
  20. for rows.Next() {
  21. var cid int
  22. if err = rows.Scan(&cid); err != nil {
  23. log.Error("ParseVideos row.Scan() error(%v)", err)
  24. return
  25. }
  26. delIds = append(delIds, cid)
  27. }
  28. if err = rows.Err(); err != nil {
  29. log.Error("d.deletedVideos.Query error(%v)", err)
  30. }
  31. return
  32. }
  33. // FinishDelVideos updates the submit status from 1 to 0
  34. func (d *Dao) FinishDelVideos(c context.Context, delIds []int) (err error) {
  35. for _, v := range delIds {
  36. if _, err = d.DB.Exec(c, _finishDelVideo, v); err != nil {
  37. log.Error("FinishDelVideos Error: %v", v, err)
  38. return
  39. }
  40. }
  41. return
  42. }
  43. // PpDelVideos postpones the archive's videos submit in 30 mins
  44. func (d *Dao) PpDelVideos(c context.Context, delIds []int) (err error) {
  45. var delay = time.Now().Unix() + int64(d.conf.UgcSync.Frequency.ErrorWait)
  46. for _, v := range delIds {
  47. if _, err = d.DB.Exec(c, _ppDelVideos, delay, v); err != nil {
  48. log.Error("PpDelVideos, failed to delay: (%v,%v), Error: %v", delay, v, err)
  49. return
  50. }
  51. }
  52. return
  53. }