async def acknowledge_op(sid, message): print("Op received", sid) data = json.loads(message) op_id = data['op_id'] print("Op id", op_id) op_found = db.get_op(op_id=op_id) if op_found is not None: # Update client op mapping - Status to acknowledged update_client_op_mapping(op_id, sid, ClientOpMappingStatus.ACKNOWLEDGED.value)
def __init__(self, id=None, operator=None, inputs=None, outputs=None, **kwargs): self._op_db = None if id is not None: self._op_db = db.get_op(op_id=id) if self._op_db is None: raise Exception("Invalid op id") else: if (inputs is not None or outputs is not None) and operator is not None: self._op_db = self.create(operator=operator, inputs=inputs, outputs=outputs, **kwargs) else: raise Exception("Invalid parameters")
def parse_op_inputs_outputs(op_dict): print(op_dict['inputs']) if op_dict.get("inputs") is not None and op_dict.get("inputs") != "null": inputs = ast.literal_eval(op_dict['inputs']) inputs_list = [] for op_id in inputs: inputs_list.append(db_manager.get_op(op_id=op_id).__dict__) op_dict['inputs'] = inputs_list else: op_dict["inputs"] = [] if op_dict.get("outputs") is not None and op_dict.get("outputs") != "null": outputs = ast.literal_eval(op_dict['outputs']) outputs_list = [] for data_id in outputs: outputs_list.append(db_manager.get_data(data_id=data_id).__dict__) op_dict['outputs'] = outputs_list else: op_dict['outputs'] = [] return op_dict
def graph_op_viewer(graph_id, graph_op_id): op = db_manager.get_op(op_id=graph_op_id) op_dict = op.__dict__ op_dict = parse_op_inputs_outputs(op_dict) return render_template('op_viewer.html', op=op_dict)
def find_op(): op = db.get_incomplete_op() if op is not None: return op else: q1 = RavQueue(name=QUEUE_HIGH_PRIORITY) q2 = RavQueue(name=QUEUE_LOW_PRIORITY) while True: op_id1 = None op_id2 = None if q1.__len__() > 0: op_id1 = q1.get(0) elif q2.__len__() > 0: op_id2 = q2.get(0) if op_id1 is None and op_id2 is None: return None ops = [op_id1, op_id2] for index, op_id in enumerate(ops): if op_id is None: continue op = db.get_op(op_id=op_id) if op.graph_id is not None: if db.get_graph(op.graph_id).status == "failed": # Change this op's status to failed if op.status != "failed": db.update_op(op, status=OpStatus.FAILED.value) continue elif db.get_graph(op.graph_id).status == "computed": if index == 0: q1.pop() elif index == 1: q2.pop() continue r = db.get_op_readiness(op) if r == "ready": if index == 0: q1.pop() elif index == 1: q2.pop() return op elif r == "parent_op_failed": if index == 0: q1.pop() elif index == 1: q2.pop() # Change this op's status to failed if op.status != "failed": db.update_op(op, status=OpStatus.FAILED.value) return None
async def op_completed(sid, data): # Save the results logger.debug("\nResult received {}".format(data)) data = json.loads(data) print(data) op_id = data['op_id'] logger.debug("{} {} {} {}".format(op_id, type(data['result']), data['operator'], data['result'])) op = RavOp(id=op_id) if data["status"] == "success": data = RavData(value=np.array(data['result']), dtype="ndarray") # Update op db.update_op(op._op_db, outputs=json.dumps([data.id]), status=OpStatus.COMPUTED.value) # Update client op mapping update_client_op_mapping(op_id, sid=sid, status=ClientOpMappingStatus.COMPUTED.value) db_op = db.get_op(op_id=op_id) if db_op.graph_id is not None: last_op = db.get_last_graph_op(graph_id=db_op.graph_id) if last_op.id == op_id: db.update(name="graph", id=db_op.graph_id, status=GraphStatus.COMPUTED.value) else: # Update op db.update_op(op._op_db, outputs=None, status=OpStatus.FAILED.value, message=data['result']) # Update client op mapping update_client_op_mapping(op_id, sid=sid, status=ClientOpMappingStatus.FAILED.value) op_status = db.get_op_status_final(op_id=op_id) if op_status == "failed": db_op = db.get_op(op_id=op_id) db.update(name="graph", id=db_op.graph_id, status=GraphStatus.FAILED.value) graph_ops = db.get_graph_ops(graph_id=db_op.graph_id) for graph_op in graph_ops: db.update_op(op=graph_op, status=OpStatus.FAILED.value) mappings = graph_op.mappings for mapping in mappings: db.update_client_op_mapping( mapping.id, status=ClientOpMappingStatus.FAILED.value) # Emit another op to this client await emit_op(sid)