databus.go 1019 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package share
  2. import (
  3. "context"
  4. "strconv"
  5. "time"
  6. "go-common/library/log"
  7. )
  8. // PubStatDatabus pub share count into databus.
  9. func (d *Dao) PubStatDatabus(c context.Context, aid int64, share int) (err error) {
  10. type stat struct {
  11. Type string `json:"type"`
  12. ID int64 `json:"id"`
  13. Count int `json:"count"`
  14. Ts int64 `json:"timestamp"`
  15. }
  16. if err = d.statDbus.Send(c, strconv.FormatInt(aid, 10), &stat{Type: "archive", ID: aid, Count: share, Ts: time.Now().Unix()}); err != nil {
  17. log.Error("d.databus.Send error(%v)", err)
  18. }
  19. return
  20. }
  21. // PubShare pub first share to databus
  22. func (d *Dao) PubShare(c context.Context, aid int64, mid int64, ip string) (err error) {
  23. type share struct {
  24. Event string `json:"event"`
  25. Mid int64 `json:"mid"`
  26. IP string `json:"ip"`
  27. Ts int64 `json:"ts"`
  28. }
  29. if err = d.shareDbus.Send(c, strconv.FormatInt(mid, 10), &share{Event: "share", Mid: mid, IP: ip, Ts: time.Now().Unix()}); err != nil {
  30. log.Error("d.shareDbus.Send error(%v)", err)
  31. }
  32. return
  33. }