Add vertices_to_run field to VerticesOrderResponse

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-03-25 13:45:18 -03:00
commit 297f9df89f
6 changed files with 30 additions and 33 deletions

View file

@ -93,7 +93,7 @@ async def get_vertices(
# and return the same structure but only with the ids
run_id = uuid.uuid4()
graph.set_run_id(run_id)
return VerticesOrderResponse(ids=first_layer, run_id=run_id)
return VerticesOrderResponse(ids=first_layer, run_id=run_id, vertices_to_run=list(graph.vertices_to_run))
except Exception as exc:
logger.error(f"Error checking build status: {exc}")

View file

@ -228,6 +228,7 @@ class ApiKeyCreateRequest(BaseModel):
class VerticesOrderResponse(BaseModel):
ids: List[str]
run_id: UUID
vertices_to_run: List[str]
class ResultDataResponse(BaseModel):

View file

@ -442,6 +442,7 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
get().nodes.filter((node) => nodes.includes(node.id)),
get().edges
);
const errors = errorsObjs.map((obj) => obj.errors).flat();
if (errors.length > 0) {
setErrorData({
@ -450,7 +451,7 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
});
get().setIsBuilding(false);
const ids = errorsObjs.map((obj) => obj.id).flat();
console.log("ids", ids);
get().updateBuildStatus(ids, BuildStatus.ERROR);
throw new Error("Invalid nodes");
}
@ -490,6 +491,7 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
verticesIds: newIds,
verticesLayers: newLayers,
runId: runId,
verticesToRun: get().verticesBuild!.verticesToRun,
});
get().updateBuildStatus(
vertexBuildData.top_level_vertices,
@ -559,6 +561,7 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
verticesIds: string[];
verticesLayers: VertexLayerElementType[][];
runId: string;
verticesToRun: string[];
} | null
) => {
set({ verticesBuild: vertices });
@ -588,6 +591,7 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
},
updateBuildStatus: (nodeIdList: string[], status: BuildStatus) => {
const newFlowBuildStatus = { ...get().flowBuildStatus };
nodeIdList.forEach((id) => {
newFlowBuildStatus[id] = {
status,

View file

@ -139,6 +139,7 @@ export type Component = {
export type VerticesOrderTypeAPI = {
ids: Array<string>;
vertices_to_run: Array<string>;
run_id: string;
};

View file

@ -110,6 +110,7 @@ export type FlowStoreType = {
verticesIds: string[];
verticesLayers: VertexLayerElementType[][];
runId: string;
verticesToRun: string[];
} | null
) => void;
addToVerticesBuild: (vertices: string[]) => void;
@ -118,6 +119,7 @@ export type FlowStoreType = {
verticesIds: string[];
verticesLayers: VertexLayerElementType[][];
runId: string;
verticesToRun: string[];
} | null;
updateBuildStatus: (nodeId: string[], status: BuildStatus) => void;
revertBuiltStatusFromBuilding: () => void;

View file

@ -53,6 +53,7 @@ export async function updateVerticesOrder(
verticesLayers: VertexLayerElementType[][];
verticesIds: string[];
runId: string;
verticesToRun: string[];
}> {
return new Promise(async (resolve, reject) => {
const setErrorData = useAlertStore.getState().setErrorData;
@ -60,7 +61,6 @@ export async function updateVerticesOrder(
try {
orderResponse = await getVerticesOrder(flowId, startNodeId, stopNodeId);
} catch (error: any) {
console.log(error);
setErrorData({
title: "Oops! Looks like you missed something",
list: [error.response?.data?.detail ?? "Unknown Error"],
@ -77,30 +77,16 @@ export async function updateVerticesOrder(
});
const runId = orderResponse.data.run_id;
// if (nodeId) {
// for (let i = 0; i < verticesOrder.length; i += 1) {
// const innerArray = verticesOrder[i];
// const idIndex = innerArray.indexOf(nodeId);
// if (idIndex !== -1) {
// // If there's a nodeId, we want to run just that component and not the entire layer
// // because a layer contains dependencies for the next layer
// // and we are stopping at the layer that contains the nodeId
// verticesLayers.push([innerArray[idIndex]]);
// break; // Stop searching after finding the first occurrence
// }
// // If the targetId is not found, include the entire inner array
// verticesLayers.push(innerArray);
// }
// } else {
// verticesLayers = verticesOrder;
// }
const verticesToRun = orderResponse.data.vertices_to_run;
const verticesIds = orderResponse.data.ids;
useFlowStore.getState().updateVerticesBuild({
verticesLayers,
verticesIds,
runId,
verticesToRun,
});
resolve({ verticesLayers, verticesIds, runId });
resolve({ verticesLayers, verticesIds, runId, verticesToRun });
});
}
@ -122,8 +108,22 @@ export async function buildVertices({
if (startNodeId && stopNodeId) {
return;
}
if (!verticesBuild || startNodeId || stopNodeId) {
verticesBuild = await updateVerticesOrder(flowId, startNodeId, stopNodeId);
let verticesOrderResponse = await updateVerticesOrder(
flowId,
startNodeId,
stopNodeId
);
if (onValidateNodes) {
try {
onValidateNodes(verticesOrderResponse.verticesToRun);
} catch (e) {
return;
}
}
if (onGetOrderSuccess) onGetOrderSuccess();
verticesBuild = useFlowStore.getState().verticesBuild;
}
const verticesIds = verticesBuild?.verticesIds!;
@ -131,17 +131,6 @@ export async function buildVertices({
const runId = verticesBuild?.runId!;
let stop = false;
if (onGetOrderSuccess) onGetOrderSuccess();
if (onValidateNodes) {
try {
const nodes = useFlowStore.getState().nodes;
onValidateNodes(nodes.map((node) => node.id));
} catch (e) {
return;
}
}
useFlowStore.getState().updateBuildStatus(verticesIds, BuildStatus.TO_BUILD);
useFlowStore.getState().setIsBuilding(true);
let currentLayerIndex = 0; // Start with the first layer