如何获取rq队列中作业的数量?

3

我正在使用rq和RedisToGo。如何获取队列中作业的数量?我在文档中找不到它的说明(使用Python)。

当我尝试:

print "Before: ", len(q.jobs)
result = q.enqueue(worker.A)
result = q.enqueue(worker.B)
print "After: ", len(q.jobs)

这两次都只是返回了0。

1个回答

4

对于 RQ,您应该能够获取队列中作业的 len

from rq import Queue

queue = Queue()
len(queue)

2
好像还有一个q.count属性。https://github.com/nvie/rq/blob/master/rq/queue.py#L85-L88 - undefined
1
q.countlen(queue.jobs)快得多。 - undefined
1
len(q)的源代码实际上是def __len__(self): return self.count,因此不需要使用len(q.jobs) - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接