def crud_output(output_id): output = Output.query.filter(Output.id==output_id).one() if request.method == 'GET': return jsonify(output.to_dict()) if request.method == 'DELETE': if output.is_pending: return {"error": "Please wait for the Output to finish running before deleting it"}, 500 output.delete(soft=False) db_session.delete(output) db_session.commit() return {"status": "OK"}
def delete(): # Deletes the session with given id (including json file) session_id = request.args.get('sid', None) if session_id is None or session_id == '': return make_response(jsonify({'errors': True, 'msg': 'No session id provided'}), 400) username = "******" user_id = 0 if g.user.is_authenticated: username = g.user.username user_id = g.user.id if not user_id and not app.config['ALLOW_UNAUTHENTICATED_USER_DELETE']: # Unauthenticated users can't delete sessions return make_response(jsonify({'errors': True, 'msg': 'Unauthenticated user'}), 401) instance = Session.query.filter_by(id=session_id).first() if not instance: return make_response(jsonify({'errors': True, 'msg': 'Session not found'}), 400) if user_id != instance.user_id: return make_response(jsonify({'errors': True, 'msg': 'Unnauthorized user'}), 401) # Do delete... name = instance.name db_session.delete(instance) db_session.commit() file_path = '%s/%s/%s.json' % (app.config['SESSIONS_FOLDER_PATH'], instance.user_id, session_id) try: os.remove(file_path) except OSError: # No probme if file does not exist pass # Compute currently available sessions for the user (so that forntend does not need to # make an extra request to update the panel) user_sessions = get_available_sessions_for_user(user_id, username) demo_sessions = get_availavle_demo_sessions() return make_response(jsonify({'errors': False, 'name': name, 'id': session_id, 'userSessions': user_sessions, 'demoSessions': demo_sessions }), 200)
def update_batch(): data = request.get_json() try: ci_commit = CiCommit.get_or_create( session=db_session, hexsha=request.json['git_commit_sha'], project_id=request.json['project'], data=data, ) except: return f"404 ERROR:\n ({request.json['project']}): There is an issue with your commit id ({request.json['git_commit_sha']})", 404 batch = ci_commit.get_or_create_batch(data['batch_label']) # prefix_output_dir for backward-compatibility batch.batch_dir_override = data.get("batch_dir", data.get("prefix_output_dir")) # Clients can store any metadata in each batch. # Currently it's used by `qa optimize` to store info on iterations if not batch.data: batch.data = {} batch_data = request.json.get('data', {}) # And each batch can have changes vs its commit's config and metrics. # The use case is usually working locally with `qa --share` and # seeing updated visualizations and metrics. if "qaboard_config" in data and data["qaboard_config"] != ci_commit.data[ "qatools_config"]: batch.data["config"] = data["qaboard_config"] if "qaboard_metrics" in data and data["qaboard_metrics"] != ci_commit.data[ "qatools_metrics"]: batch.data["qatools_metrics"] = data["qaboard_metrics"] batch.data = {**batch.data, **batch_data} # Save info on each "qa batch" command in the batch, mainly to list them in logs command = request.json.get('command') if command: batch.data["commands"] = {**batch.data.get('commands', {}), **command} flag_modified(batch, "data") # It's a `qa optimzize` experiment if batch_data.get('optimization'): if 'best_iter' in batch_data: # we will save the outputs from the best iteration in the batch, # so first we need to remove any previous best results for o in batch.outputs: if o.output_type != 'optim_iteration': o.delete(soft=False) db_session.add(batch) db_session.commit() # Move results from the best iteration in this batch batch_batch_label = batch_data['last_iteration_label'] best_batch = ci_commit.get_or_create_batch(batch_batch_label) for o in best_batch.outputs: o.output_dir_override = str(o.output_dir) o.batch = batch db_session.add(o) db_session.commit() for b in ci_commit.batches: if b.label.startswith( f"{data['batch_label']}|iter" ) and b.label != batch_data['last_iteration_label']: print(f'Deleting previous iteration {b.label}') if b.label != batch_data['last_iteration_label']: db_session.delete(b) db_session.add(batch) db_session.commit() return jsonify({"status": "OK", "id": batch.id})