del_upper.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package ugc
  2. import (
  3. "context"
  4. "time"
  5. "go-common/library/database/sql"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _deletedUp = "SELECT mid FROM ugc_uploader WHERE toinit = 2 AND deleted = 1 AND retry < unix_timestamp(now()) LIMIT 1"
  10. _finishDelUp = "UPDATE ugc_uploader SET toinit = 0 WHERE mid = ? AND deleted = 1"
  11. _ppDelUp = "UPDATE ugc_uploader SET retry = ? WHERE mid = ? AND deleted = 1"
  12. _upArcs = "SELECT aid FROM ugc_archive WHERE mid = ? AND deleted = 0 LIMIT 50"
  13. _upCountArc = "SELECT count(1) FROM ugc_archive WHERE mid = ? AND deleted = 0"
  14. )
  15. // DeletedUp picks the deleted uppers, toinit = 2 and deleted = 1
  16. func (d *Dao) DeletedUp(c context.Context) (mid int64, err error) {
  17. err = d.DB.QueryRow(c, _deletedUp).Scan(&mid)
  18. return
  19. }
  20. // FinishDelUp updates the submit toinit from 2 to 0
  21. func (d *Dao) FinishDelUp(c context.Context, mid int64) (err error) {
  22. if _, err = d.DB.Exec(c, _finishDelUp, mid); err != nil {
  23. log.Error("FinishDelUp Error: %v", mid, err)
  24. }
  25. return
  26. }
  27. // PpDelUp postpones the upper's videos submit in 30 mins
  28. func (d *Dao) PpDelUp(c context.Context, mid int64) (err error) {
  29. var delay = time.Now().Unix() + int64(d.conf.UgcSync.Frequency.ErrorWait)
  30. if _, err = d.DB.Exec(c, _ppDelUp, delay, mid); err != nil {
  31. log.Error("PostponeArc, failed to delay: (%v,%v), Error: %v", delay, mid, err)
  32. }
  33. return
  34. }
  35. // CountUpArcs counts the upper's archives
  36. func (d *Dao) CountUpArcs(c context.Context, mid int64) (count int64, err error) {
  37. if err = d.DB.QueryRow(c, _upCountArc, mid).Scan(&count); err != nil {
  38. log.Error("d.CountUpArcs.Query error(%v)", err)
  39. }
  40. return
  41. }
  42. // UpArcs picks 50 arcs of the upper
  43. func (d *Dao) UpArcs(c context.Context, mid int64) (aids []int64, err error) {
  44. var rows *sql.Rows
  45. if rows, err = d.DB.Query(c, _upArcs, mid); err != nil { // get the qualified aid to sync
  46. log.Error("d.UpArcs.Query error(%v)", err)
  47. return
  48. }
  49. defer rows.Close()
  50. for rows.Next() {
  51. var aid int64
  52. if err = rows.Scan(&aid); err != nil {
  53. log.Error("ParseVideos row.Scan() error(%v)", err)
  54. return
  55. }
  56. aids = append(aids, aid)
  57. }
  58. if err = rows.Err(); err != nil {
  59. log.Error("d.UpArcs.Query error(%v)", err)
  60. }
  61. return
  62. }