def get_op_stats(self): """Get stats of all ops""" ops = db.get_graph_ops(graph_id=self.id) pending_ops = 0 computed_ops = 0 computing_ops = 0 failed_ops = 0 for op in ops: if op.status == "pending": pending_ops += 1 elif op.status == "computed": computed_ops += 1 elif op.status == "computing": computing_ops += 1 elif op.status == "failed": failed_ops += 1 total_ops = len(ops) return { "total_ops": total_ops, "pending_ops": pending_ops, "computing_ops": computing_ops, "computed_ops": computed_ops, "failed_ops": failed_ops }
def ops(self): ops = db.get_graph_ops(self.id) return [Op(id=op.id) for op in ops]
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)