def get(self, id=None, project_id=None): """get.""" logs_limit = request.args.get('logs_limit', default=-1, type=int) project = db.session.query(Project).filter_by(id=project_id).first() if project is None: return jsonify({ 'project': None, 'message': 'No interface defined for URL.' }), 404 if id is None: path = request.args.get('path_name', default=None) if path is not None: result = db.session.query(Result).filter_by( path_name=path).first() if result is None: return jsonify({ 'result': None, 'message': 'Result path \'%s\' is not found' % path }), 400 return jsonify({'result': result.serialize}) collect_results(project) results = db.session.query(Result).\ filter_by(project_id=project_id).\ filter_by(is_unregistered=False).\ all() # NOTE: To improve performance, aggregate commit phase. By set # `commit=False`, implicit transaction is not closed, UPDATE query # is not committed. Consequently a process of serializing does not # have to call SELECT query again. for result in results: crawl_result(result, commit=False) db.session.commit() rs = [r.serialize_with_sampled_logs(logs_limit) for r in results] return jsonify({'results': rs}) else: result = db.session.query(Result).\ filter_by(id=id).\ filter_by(is_unregistered=False).\ first() if result is None: return jsonify({ 'result': None, 'message': 'No interface defined for URL.' }), 404 result = crawl_result(result) return jsonify( {'result': result.serialize_with_sampled_logs(logs_limit)})
def create(cls, path_name=None, name=None): """initialize an instance and save it to db.""" project = cls(path_name, name) DB_SESSION.add(project) DB_SESSION.commit() collect_results(project, force=True)
def get(self, id=None, project_id=None): """get.""" logs_limit = request.args.get('logs_limit', default=-1, type=int) project = DB_SESSION.query(Project).\ filter_by(id=project_id).\ first() if project is None: return jsonify({ 'project': None, 'message': 'No interface defined for URL.' }), 404 if id is None: collect_results(project) results = DB_SESSION.query(Result).\ filter_by(project_id=project_id).\ filter_by(is_unregistered=False).\ all() for result in results: result = crawl_result(result) return jsonify({ 'results': [ r.serialize_with_sampled_logs(logs_limit) for r in results ] }) else: result = DB_SESSION.query(Result).\ filter_by(id=id).\ filter_by(is_unregistered=False).\ first() if result is None: return jsonify({ 'result': None, 'message': 'No interface defined for URL.' }), 404 result = crawl_result(result) return jsonify({ 'result': result.serialize_with_sampled_logs(logs_limit) })
def get(self, id=None, project_id=None): """get.""" project = DB_SESSION.query(Project).\ filter_by(id=project_id).\ first() if project is None: return jsonify({ 'project': None, 'message': 'No interface defined for URL.' }), 404 if id is None: collect_results(project) results = DB_SESSION.query(Result).\ filter_by(project_id=project_id).\ filter_by(is_unregistered=False).\ all() for result in results: result = crawl_result(result.id) return jsonify({'results': [r.serialize for r in results]}) else: result = DB_SESSION.query(Result).\ filter_by(id=id).\ filter_by(is_unregistered=False).\ first() if result is None: return jsonify({ 'result': None, 'message': 'No interface defined for URL.' }), 404 result = crawl_result(result.id) return jsonify({'result': result.serialize})