reply.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/job/main/videoup-report/model/archive"
  6. "go-common/app/job/main/videoup-report/model/email"
  7. "go-common/library/log"
  8. "go-common/library/queue/databus/report"
  9. )
  10. func (s *Service) arcReply(c context.Context, a *archive.Archive, replySwitch int64) (err error) {
  11. if replySwitch != archive.ReplyOn && replySwitch != archive.ReplyOff {
  12. log.Error("arcReply aid(%d) archive replySwitch(%d) 's state is unknow!", a.ID, replySwitch)
  13. return
  14. }
  15. replyState, _ := s.dataDao.CheckReply(c, a.ID)
  16. //删除之前的重试机会,避免延迟重试覆盖最新结果
  17. //s.removeRetry(c, a.ID, email.RetryActionReply)
  18. if replySwitch == archive.ReplyOn {
  19. err = s.openReply(c, a, replyState)
  20. } else {
  21. err = s.closeReply(c, a, replyState)
  22. }
  23. return
  24. }
  25. func (s *Service) openReply(c context.Context, a *archive.Archive, oldState int64) (err error) {
  26. if a == nil {
  27. return
  28. }
  29. if err = s.dataDao.OpenReply(c, a.ID, a.Mid); err != nil {
  30. log.Error("openReply s.dataDao.OpenReply(%d,%d) error(%v)", a.ID, a.Mid, err)
  31. s.addRetry(c, a.ID, email.RetryActionReply, archive.ReplyOn, oldState)
  32. return
  33. }
  34. if oldState == archive.ReplyOn {
  35. return
  36. }
  37. if oldState != archive.ReplyOn && oldState != archive.ReplyOff {
  38. oldState = archive.ReplyDefault
  39. }
  40. s.logJob(a, archive.ReplyDesc[archive.ReplyOn], archive.ReplyDesc[oldState])
  41. return
  42. }
  43. func (s *Service) closeReply(c context.Context, a *archive.Archive, oldState int64) (err error) {
  44. if a == nil {
  45. return
  46. }
  47. if err = s.dataDao.CloseReply(c, a.ID, a.Mid); err != nil {
  48. log.Error("closeReply s.dataDao.CloseReply(%d,%d) error(%v)", a.ID, a.Mid, err)
  49. s.addRetry(c, a.ID, email.RetryActionReply, archive.ReplyOff, oldState)
  50. return
  51. }
  52. if oldState == archive.ReplyOff {
  53. return
  54. }
  55. if oldState != archive.ReplyOn && oldState != archive.ReplyOff {
  56. oldState = archive.ReplyDefault
  57. }
  58. s.logJob(a, archive.ReplyDesc[archive.ReplyOff], archive.ReplyDesc[oldState])
  59. return
  60. }
  61. func (s *Service) logJob(a *archive.Archive, action string, oldAction string) {
  62. info := &report.ManagerInfo{
  63. Uname: "videoup-job",
  64. UID: 399,
  65. Business: archive.LogBusJob,
  66. Type: archive.LogTypeReply,
  67. Oid: a.ID,
  68. Action: action,
  69. Ctime: time.Now(),
  70. Index: []interface{}{a.State},
  71. Content: map[string]interface{}{"old": oldAction},
  72. }
  73. log.Info("logJob (%+v)", info)
  74. report.Manager(info)
  75. }
  76. func isOpenReplyState(state int) (val int) {
  77. if archive.NormalState(state) || state == archive.StateForbidFixed {
  78. val = 1
  79. }
  80. return
  81. }