task_consumer.go 656 B

1234567891011121314151617181920212223242526272829303132
  1. package archive
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/library/log"
  6. )
  7. const (
  8. _consumerOnlineSQL = "SELECT uid FROM task_consumer WHERE uid IN (%s) AND state=1"
  9. )
  10. //ConsumerOnline get online task_consumer
  11. func (d *Dao) ConsumerOnline(c context.Context, uids string) (ids []int64, err error) {
  12. rows, err := d.db.Query(c, fmt.Sprintf(_consumerOnlineSQL, uids))
  13. if err != nil {
  14. log.Error("d.db.Query(%s, %v) error(%v)", _consumerOnlineSQL, uids, err)
  15. return
  16. }
  17. defer rows.Close()
  18. for rows.Next() {
  19. var id int64
  20. if err = rows.Scan(&id); err != nil {
  21. log.Error("rows.Scan error(%v)", err)
  22. return
  23. }
  24. ids = append(ids, id)
  25. }
  26. return
  27. }