Google App Engine (Java) TaskQueue API: how to query number of running/pending tasks?
Is it possible to programmatically query the Task Queue API to see how many tasks are currently executing/pending?
I don't see any way to do this in the API, and so I resorted to creating objects in the Datastore to represent queued tasks. When run, the tasks then remove their corresponding entry from the Datastore.
As you can imagine, it's easy for this to get out of sync. I'd actually be 开发者_如何学Gopretty happy just to be able to get a simple count of tasks in the queue for a given queue name.
Unfortunately, there is no API you can use to get information about the task queues. However, this is something I believe the team has in mind for the future (a programmatic interface to get stats that we currently see on the dashboard, like task count).
As announced in April, Task Queue Statistics are currently available to Trusted Testers. Task Queue Statistics allows you to fetch statistics and information about your task queue from within your application. http://googleappengine.blogspot.com.au/2012_04_01_archive.html
A QueueStatistics class can provide you information about stats such as number of tasks in a queue and tasks that are currently executed.
- Python: https://cloud.google.com/appengine/docs/python/taskqueue/queue_statistics
- Java: https://cloud.google.com/appengine/docs/java/javadoc/com/google/appengine/api/taskqueue/QueueStatistics
In java:
QueueFactory.getQueue(queueName).fetchStatistics().getNumTasks();
精彩评论