msg.go 877 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package service
  2. import (
  3. "context"
  4. "time"
  5. blkmodel "go-common/app/admin/main/credit/model/blocked"
  6. "go-common/library/log"
  7. )
  8. func (s *Service) msgproc() {
  9. // NOTE: chan
  10. s.wg.Add(1)
  11. go func() {
  12. var (
  13. c = context.TODO()
  14. sysMsg *blkmodel.SysMsg
  15. ok bool
  16. title, content string
  17. )
  18. defer s.wg.Done()
  19. for {
  20. if sysMsg, ok = <-s.MsgCh; !ok {
  21. log.Info("msgproc s.msgCh proc stop")
  22. return
  23. }
  24. if sysMsg == nil {
  25. select {
  26. case <-time.After(3 * time.Minute):
  27. continue
  28. case <-s.stop:
  29. return
  30. }
  31. }
  32. title, content = blkmodel.MsgInfo(sysMsg)
  33. if err := s.msgDao.SendSysMsg(c, sysMsg.MID, title, content); err != nil {
  34. log.Info("mid(%d) title(%s) content(%s) send sysMsg error(%v)", sysMsg.MID, title, content, err)
  35. continue
  36. }
  37. time.Sleep(100 * time.Millisecond)
  38. }
  39. }()
  40. }