def get(self, job_id): """GET Job GET request for an Job of id job_id Parameters ---------- job_id : string ObjectId of the requested Job. Returns ------- response : dict JSON response to this GET Request """ # check if a user is logged in _filter = get_user_bound_filter(roles=['admin']) # get the Job job = Job.get(job_id, filter=_filter) # return if job is None: return {'status': 404, 'message': 'No Job of id %s' % job_id} else: return job.to_dict(stringify=True)
def run_job(job_id): # check if a user is logged in _filter = get_user_bound_filter(roles=['admin']) # get the requested Job job = Job.get(job_id, filter=_filter) if job is None: return jsonify({ 'status': 404, 'message': 'No Job of id %s' % job_id }), 404 # start the job if job.started is None: # try: job.start() # except Exception as e: # return jsonify({'status': 500, 'message': str(e)}), 500 # return the job return jsonify(job.to_dict(stringify=True)), 202 # job was already started else: return jsonify({ 'status': 409, 'message': 'The job %s was already started' % job_id }), 409
def delete(self, job_id): # check if a user is logged in # check if a user is logged in _filter = get_user_bound_filter(roles=['admin']) # get the job job = Job.get(job_id, filter=_filter) if job is None: return { 'status': 404, 'message': 'No job of id %s found' % job_id }, 404 # delete if job.delete(): return { 'status': 200, 'acknowledged': True, 'message': 'Job of ID %s deleted.' % job_id }, 200 else: return { 'status': 500, 'message': 'Something went horribly wrong.' }, 500
def post(self, job_id): """POST request Handle a POST request to the job of job_id. This will update the job, as long as it was created, but not jet started. The data to be updated has to be sent as request data. Parameters ---------- job_id : string ObjectId of the requested Job. Returns ------- response : dict JSON response to this POST Request """ # check if a user is logged in _filter = get_user_bound_filter(roles=['admin']) # get the job job = Job.get(job_id, filter=_filter) if job is None: return {'status': 404, 'message': 'No Job of id %s' % job_id} # get the data data = request.get_json() if len(data.keys()) == 0: return {'stauts': 412, 'message': 'No data received.'}, 412 try: job.update(data=data) except Exception as e: return {'status': 500, 'message': str(e)} return job.to_dict(stringify=True), 200