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

Merge pull request #128 from scitran/job-stats

Add simple job stats query
parents 3f13a38d a1cdf255
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,25 @@ 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 = {}
# Don't randomly omit keys that are zero
for s in JOB_STATES:
states[s] = 0
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