databus.go 894 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package dao
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/service/main/sms/model"
  6. "go-common/library/log"
  7. )
  8. const _retry = 3
  9. // PubSingle pub single sms to databus
  10. func (d *Dao) PubSingle(ctx context.Context, l *model.ModelSend) (err error) {
  11. for i := 0; i < _retry; i++ {
  12. if err = d.databus.Send(ctx, l.Mobile, l); err == nil {
  13. break
  14. }
  15. time.Sleep(10 * time.Millisecond)
  16. }
  17. if err != nil {
  18. log.Error("PubSingle(%+v) error(%v)", l, err)
  19. return
  20. }
  21. log.Info("PubSingle(%+v) success.", l)
  22. return
  23. }
  24. // PubBatch pub batch sms to databus
  25. func (d *Dao) PubBatch(ctx context.Context, l *model.ModelSend) (err error) {
  26. for i := 0; i < _retry; i++ {
  27. if err = d.databus.Send(ctx, l.Code, l); err == nil {
  28. break
  29. }
  30. time.Sleep(10 * time.Millisecond)
  31. }
  32. if err != nil {
  33. log.Error("PubBatch(%+v) error(%v)", l, err)
  34. return
  35. }
  36. log.Info("PubBatch(%+v) success.", l)
  37. return
  38. }