diff --git a/api/jobs.py b/api/jobs.py index b51953a6033591026732f07da49deb0039d4d0f1..0941b43d24b7d23c2752ce6b06bc7edb14594364 100644 --- a/api/jobs.py +++ b/api/jobs.py @@ -220,21 +220,15 @@ class Jobs(base.RequestHandler): def stats(self): if not self.superuser_request: self.abort(403, 'Request requires superuser') + + # A simple count of jobs by state 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 + stats = {s: 0 for s in JOB_STATES} + stats.update({r['_id']: r['count'] for r in result}) - return states + return stats def next(self): """