Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Tasks status out of sync #802

Merged
merged 3 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,11 @@ export const NodeExecutionDetailsPanelContent: React.FC<
useNodeExecutionsById();

const nodeExecution = useMemo(() => {
return values(nodeExecutionsById).find(node =>
const finalExecution = values(nodeExecutionsById).find(node =>
isEqual(node.id, nodeExecutionId),
);

return finalExecution;
}, [nodeExecutionId, nodeExecutionsById]);

const [isReasonsVisible, setReasonsVisible] = useState<boolean>(false);
Expand Down Expand Up @@ -299,7 +301,7 @@ export const NodeExecutionDetailsPanelContent: React.FC<
return () => {
isCurrent = false;
};
});
}, [nodeExecution]);

useEffect(() => {
let isCurrent = true;
Expand Down Expand Up @@ -408,7 +410,7 @@ export const NodeExecutionDetailsPanelContent: React.FC<
isGateNode,
);
return computedPhase;
}, [nodeExecution?.closure.phase, isGateNode]);
}, [nodeExecution, isGateNode]);

const isRunningPhase = useMemo(
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const parseSpanData = (
export const getOperationsFromWorkflowExecutionMetrics = (
data: Admin.WorkflowExecutionGetMetricsResponse,
): string[] => {
const operationIds = uniq(
const operationIds = uniq<string>(
traverse(data)
.paths()
.filter(path => path[path.length - 1] === 'operationId')
Expand Down Expand Up @@ -173,7 +173,7 @@ export const getDuration = (
export const getExecutionMetricsOperationIds = (
data: Admin.WorkflowExecutionGetMetricsResponse,
): string[] => {
const operationIds = uniq(
const operationIds = uniq<string>(
traverse(data)
.paths()
.filter(path => path[path.length - 1] === 'operationId')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, {
PropsWithChildren,
useCallback,
useContext,
useEffect,
useState,
Expand All @@ -11,7 +10,7 @@ import {
NodeExecutionsById,
WorkflowNodeExecutionsContext,
} from 'components/Executions/contexts';
import { isEqual, keyBy, merge, mergeWith } from 'lodash';
import { isEqual, keyBy, merge, mergeWith, cloneDeep } from 'lodash';
import { dNode } from 'models/Graph/types';
import {
NodeExecutionDynamicWorkflowQueryResult,
Expand Down Expand Up @@ -187,33 +186,31 @@ export const WorkflowNodeExecutionsProvider = ({
}
}, [shouldUpdate]);

const setCurrentNodeExecutionsById = useCallback(
(
newNodeExecutionsById: NodeExecutionsById,
checkForDynamicParents?: boolean,
): void => {
setNodeExecutionsById(prev => {
const newNodes = mergeWith(
{ ...prev },
{ ...newNodeExecutionsById },
mergeNodeExecutions,
);
if (
JSON.stringify(prev, mapStringifyReplacer) ===
JSON.stringify(newNodes, mapStringifyReplacer)
) {
return prev;
}
const setCurrentNodeExecutionsById = (
newNodeExecutionsById: NodeExecutionsById,
checkForDynamicParents?: boolean,
): void => {
const mergedNodes = mergeWith(
cloneDeep(nodeExecutionsById),
cloneDeep(newNodeExecutionsById),
mergeNodeExecutions,
);

if (checkForDynamicParents) {
setShouldUpdate(true);
}
setNodeExecutionsById(prev => {
if (
JSON.stringify(prev, mapStringifyReplacer) ===
JSON.stringify(mergedNodes, mapStringifyReplacer)
) {
return prev;
}

return newNodes;
});
},
[],
);
if (checkForDynamicParents) {
setShouldUpdate(true);
}

return mergedNodes;
});
};

return (
<WorkflowNodeExecutionsContext.Provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,15 @@ export const stringifyIsEqual = (a: any, b: any) => {
);
};

export const mergeNodeExecutions = (val, srcVal, _key) => {
export const mergeNodeExecutions = (val, srcVal, _topkey) => {
const retVal = mergeWith(val, srcVal, (target, src, _key) => {
if (!target) {
return src;
}
const clonedTarget = cloneDeep(target);
const clonedSrc = cloneDeep(src);
if (clonedSrc instanceof Map) {
return clonedSrc;
if (src instanceof Map) {
return src;
}
const finaVal =
typeof clonedSrc === 'object'
? merge(clonedTarget, clonedSrc)
: clonedSrc;
const finaVal = typeof src === 'object' ? merge(target, src) : src;
return finaVal;
});
return retVal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { isParentNode } from 'components/Executions/utils';
import { isStartOrEndNode } from 'models/Node/utils';
import { NodeExecutionsById } from 'components/Executions/contexts';
import { cloneDeep, values } from 'lodash';
import {
getDisplayName,
getSubWorkflowFromId,
Expand Down Expand Up @@ -509,11 +510,14 @@ export interface TransformerWorkflowToDag {
export const transformerWorkflowToDag = (
workflow: CompiledWorkflowClosure,
dynamicToMerge: any | null = null,
nodeExecutionsById = {},
inputNodeExecutionsById: NodeExecutionsById = {},
): TransformerWorkflowToDag => {
const { primary } = workflow;
const staticExecutionIdsMap = {};

// clone nodeExecutionsById to prevent mutation
const nodeExecutionsById = cloneDeep(inputNodeExecutionsById);

const primaryWorkflowRoot = createDNode({
compiledNode: {
id: startNodeId,
Expand Down