databus.go 694 B

1234567891011121314151617181920212223242526272829303132
  1. package pub
  2. import (
  3. "context"
  4. "strconv"
  5. "time"
  6. "go-common/library/log"
  7. )
  8. type statMessage struct {
  9. Type string `json:"type"`
  10. ID int64 `json:"id"`
  11. Count int64 `json:"count"`
  12. TimeStamp int64 `json:"timestamp"`
  13. }
  14. // PubStats update object's fav count
  15. func (d *Dao) PubStats(c context.Context, typ int8, oid int64, cnt int64) (err error) {
  16. if name, ok := d.consumersMap[typ]; ok {
  17. msg := &statMessage{
  18. Type: name,
  19. ID: oid,
  20. Count: cnt,
  21. TimeStamp: time.Now().Unix(),
  22. }
  23. if err = d.databus2.Send(c, strconv.FormatInt(oid, 10), msg); err != nil {
  24. log.Error("d.databus2.Send(%d,%d,%v) error(%v)", typ, oid, msg, err)
  25. }
  26. }
  27. return
  28. }