Skip to content

Commit

Permalink
Gear logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kofalt committed Mar 28, 2017
1 parent d37fa65 commit 85fd6b3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 2 additions & 0 deletions api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def prefix(path, routes):
route('/<:[^/]+>', JobHandler),
route('/<:[^/]+>/config.json', JobHandler, h='get_config'),
route('/<:[^/]+>/retry', JobHandler, h='retry', m=['POST']),
route('/<:[^/]+>/logs', JobHandler, h='get_logs', m=['GET']),
route('/<:[^/]+>/logs', JobHandler, h='add_logs', m=['POST']),
]),
route('/gears', GearsHandler),
prefix('/gears', [
Expand Down
41 changes: 41 additions & 0 deletions api/jobs/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,47 @@ def put(self, _id):

Queue.mutate(j, mutation)

def get_logs(self, _id):
"""Get a job's logs"""

job = Job.get(_id)
if job is None:
self.abort(404, 'Job not found')

# Permission check
if not self.superuser_request:
for x in job.inputs:
job.inputs[x].check_access(self.uid, 'ro')
# Unlike jobs-add, explicitly not checking write access to destination.

log = config.db.job_logs.find_one({'_id': _id})

if log is None:
return { '_id': _id, 'logs': [] }
else:
return log

def add_logs(self, _id):
"""Add to a job's logs"""

if not self.superuser_request:
self.abort(403, 'Request requires superuser')

doc = self.request.json

job = Job.get(_id)
if job is None:
self.abort(404, 'Job not found')

log = config.db.job_logs.find_one({'_id': _id})

if log is None: # Race
config.db.job_logs.insert_one({'_id': _id, 'logs': []})

config.db.job_logs.update({'_id': _id}, {'$push':{'logs':{'$each':doc}}})
return


def retry(self, _id):
""" Retry a job.
Expand Down
1 change: 0 additions & 1 deletion api/jobs/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def __init__(self, gear_id, inputs, destination=None, tags=None,
'id': None
}


self.gear_id = gear_id
self.inputs = inputs
self.destination = destination
Expand Down

0 comments on commit 85fd6b3

Please sign in to comment.