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 # and return the same structure but only with the ids
run_id = uuid.uuid4() run_id = uuid.uuid4()
graph.set_run_id(run_id) 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: except Exception as exc:
logger.error(f"Error checking build status: {exc}") logger.error(f"Error checking build status: {exc}")

View file

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

View file

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

View file

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

View file

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

View file

@ -53,6 +53,7 @@ export async function updateVerticesOrder(
verticesLayers: VertexLayerElementType[][]; verticesLayers: VertexLayerElementType[][];
verticesIds: string[]; verticesIds: string[];
runId: string; runId: string;
verticesToRun: string[];
}> { }> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
const setErrorData = useAlertStore.getState().setErrorData; const setErrorData = useAlertStore.getState().setErrorData;
@ -60,7 +61,6 @@ export async function updateVerticesOrder(
try { try {
orderResponse = await getVerticesOrder(flowId, startNodeId, stopNodeId); orderResponse = await getVerticesOrder(flowId, startNodeId, stopNodeId);
} catch (error: any) { } catch (error: any) {
console.log(error);
setErrorData({ setErrorData({
title: "Oops! Looks like you missed something", title: "Oops! Looks like you missed something",
list: [error.response?.data?.detail ?? "Unknown Error"], list: [error.response?.data?.detail ?? "Unknown Error"],
@ -77,30 +77,16 @@ export async function updateVerticesOrder(
}); });
const runId = orderResponse.data.run_id; const runId = orderResponse.data.run_id;
// if (nodeId) { const verticesToRun = orderResponse.data.vertices_to_run;
// 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 verticesIds = orderResponse.data.ids; const verticesIds = orderResponse.data.ids;
useFlowStore.getState().updateVerticesBuild({ useFlowStore.getState().updateVerticesBuild({
verticesLayers, verticesLayers,
verticesIds, verticesIds,
runId, runId,
verticesToRun,
}); });
resolve({ verticesLayers, verticesIds, runId }); resolve({ verticesLayers, verticesIds, runId, verticesToRun });
}); });
} }
@ -122,8 +108,22 @@ export async function buildVertices({
if (startNodeId && stopNodeId) { if (startNodeId && stopNodeId) {
return; return;
} }
if (!verticesBuild || startNodeId || stopNodeId) { 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!; const verticesIds = verticesBuild?.verticesIds!;
@ -131,17 +131,6 @@ export async function buildVertices({
const runId = verticesBuild?.runId!; const runId = verticesBuild?.runId!;
let stop = false; 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().updateBuildStatus(verticesIds, BuildStatus.TO_BUILD);
useFlowStore.getState().setIsBuilding(true); useFlowStore.getState().setIsBuilding(true);
let currentLayerIndex = 0; // Start with the first layer let currentLayerIndex = 0; // Start with the first layer