add method to get queue length

This commit is contained in:
Brian Matheson 2019-04-15 14:46:51 -04:00
parent 74b927b622
commit 43ed88fe05
1 changed files with 6 additions and 0 deletions

View File

@ -68,6 +68,12 @@ func (q *Queue) Poll() ([]*Pair, error) {
return resp, err
}
func (q *Queue) Len() (int, error) {
prefix := fmt.Sprintf("%s/", q.prefix)
resp, err := q.cli.GetPrefix(prefix, WithCountOnly())
return resp, err
}
func (q *Queue) Watch(fn func(q *Queue, pair *Pair)) error {
prefix := fmt.Sprintf("%s/", q.prefix)
pairs, err := q.cli.GetPrefix(prefix, etcd.WithLimit(1), sort())