def func_wrapper(*args, **kwargs): if not task.exists(redis, kwargs['task_id']): abort( flask.make_response( flask.jsonify(message="task %s unknown" % kwargs['task_id']), 404)) return func(*args, **kwargs)
def get_file(task_id, filename): if not task.exists(redis, task_id): flask.abort(flask.make_response(flask.jsonify(message="task %s unknown" % task_id), 404)) content = task.get_file(redis, task_id, filename) if content is None: flask.abort(flask.make_response( flask.jsonify(message="cannot find file %s for task %s" % (filename, task_id)), 404)) response = flask.make_response(content) return response
def get_log(task_id): if not task.exists(redis, task_id): flask.abort(flask.make_response(flask.jsonify(message="task %s unknown" % task_id), 404)) content = task.get_log(redis, task_id) if content is None: flask.abort(flask.make_response(flask.jsonify(message="no logs for task %s" % task_id), 404)) response = flask.make_response(content) response.mimetype = 'text/plain' return response
def task_readonly_control(task_id): if task_id is None: abort(flask.make_response(flask.jsonify(message="task empty"), 404)) if not task.exists(redis, task_id): abort(flask.make_response(flask.jsonify(message="task %s unknown" % task_id), 404)) if not has_ability(flask.g, 'train', task_id[:2]): abort(make_response(jsonify(message="insufficient credentials for tasks %s" % task_id), 403))
def beat(task_id): duration = flask.request.args.get('duration') try: if duration is not None: duration = int(duration) except ValueError: flask.abort(flask.make_response(flask.jsonify(message="invalid duration value"), 400)) container_id = flask.request.args.get('container_id') if not task.exists(redis, task_id): flask.abort(flask.make_response(flask.jsonify(message="task %s unknown" % task_id), 404)) task.beat(redis, task_id, duration, container_id) return flask.jsonify(200)
def func_wrapper(*args, **kwargs): ok = False task_id = kwargs['task_id'] if task_id is None: abort(flask.make_response(flask.jsonify(message="task empty"), 404)) if not task.exists(redis, task_id): abort(flask.make_response(flask.jsonify(message="task %s unknown" % task_id), 404)) entity = task_id[:2] if has_ability(flask.g, 'admin_task', entity): ok = True elif has_ability(flask.g, 'train', entity) and flask.g.user.user_code == task_id[2:5]: ok = True if not ok: abort(make_response(jsonify(message="insufficient credentials for tasks %s" % task_id), 403)) return func(*args, **kwargs)
def status(task_id): if not task.exists(redis, task_id): flask.abort(flask.make_response(flask.jsonify(message="task %s unknown" % task_id), 404)) response = task.info(redis, task_id, []) return flask.jsonify(response)
def post_file(task_id, filename): if not task.exists(redis, task_id): flask.abort(flask.make_response(flask.jsonify(message="task %s unknown" % task_id), 404)) content = flask.request.get_data() task.set_file(redis, task_id, content, filename) return flask.jsonify(200)