Check if a queue is empty in Google App Engine

511 views Asked by At

I have a script that add tasks to a queue. For example:

api.py:

from google.appengine.api import taskqueue    
[...]
for u in users:
    taskqueue.add(queue_name='mailqueue', url="/api/users/send-notification/%s" % (u.id), method='GET')

I would like to check if the queue is empty and all tasks are finishing

view.py:

if queue_is_empty:
    print "Your task is finished"
1

There are 1 answers

0
Paul Collingwood On BEST ANSWER

You can use the QueueStatistics class

statsList = taskqueue.QueueStatistics.fetch([taskqueue.Queue("foo"), taskqueue.Queue("bar")])

https://cloud.google.com/appengine/docs/python/taskqueue/queue_statistics#QueueStatistics_queue