pendant.go 1022 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/job/main/usersuit/model"
  6. "go-common/library/log"
  7. )
  8. var (
  9. t = time.NewTimer(time.Minute * 5)
  10. )
  11. // startexpireproc start
  12. func (s *Service) startexpireproc() {
  13. for range t.C {
  14. s.expiredEquip(context.TODO())
  15. t.Reset(time.Minute * 10)
  16. }
  17. }
  18. // expiredEquip operator equipment info
  19. func (s *Service) expiredEquip(c context.Context) (err error) {
  20. var (
  21. mids []int64
  22. expires = time.Now().Unix()
  23. affected int64
  24. )
  25. if mids, err = s.pendantDao.ExpireEquipPendant(c, expires); err != nil || len(mids) == 0 {
  26. log.Error("s.pendantDao.ExpireEquipPendant(%d) error(%+v)", expires, err)
  27. return
  28. }
  29. for _, mid := range mids {
  30. if affected, err = s.pendantDao.UpEquipMID(c, mid); err != nil || affected == 0 {
  31. log.Error("s.pendantDao.UpEquipMID(%d) error(%+v)", mid, err)
  32. continue
  33. }
  34. s.pendantDao.DelEquipCache(c, mid)
  35. tid := mid
  36. s.addNotify(func() {
  37. s.accNotify(context.TODO(), tid, model.AccountNotifyUpdatePendant)
  38. })
  39. }
  40. return
  41. }