Skip to content
Snippets Groups Projects
Commit 6649fae1 authored by Nathaniel Kofalt's avatar Nathaniel Kofalt
Browse files

Add simple job stats query

parent 3f13a38d
No related branches found
No related tags found
No related merge requests found
......@@ -71,6 +71,7 @@ routes = [
webapp2_extras.routes.PathPrefixRoute(r'/api/jobs', [
webapp2.Route(r'/next', jobs.Jobs, handler_method='next', methods=['GET']),
webapp2.Route(r'/count', jobs.Jobs, handler_method='count', methods=['GET']),
webapp2.Route(r'/stats', jobs.Jobs, handler_method='stats', methods=['GET']),
webapp2.Route(r'/addTestJob', jobs.Jobs, handler_method='addTestJob', methods=['GET']),
webapp2.Route(r'/reap', jobs.Jobs, handler_method='reap_stale', methods=['POST']),
webapp2.Route(r'/<:[^/]+>', jobs.Job, name='job'),
......
......@@ -217,6 +217,20 @@ class Jobs(base.RequestHandler):
return config.db.jobs.count()
def stats(self):
if not self.superuser_request:
self.abort(403, 'Request requires superuser')
result = config.db.jobs.aggregate([{"$group": {"_id": "$state", "count": {"$sum": 1}}}])
# Map mongo result to a useful object
states = {}
for r in result:
key = r['_id']
val = r['count']
states[key] = val
return states
def next(self):
"""
Atomically change a 'pending' job to 'running' and returns it. Updates timestamp.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment