fix: Run evaluations loop manually always from first row (#15794)

This commit is contained in:
Mutasem Aldmour
2025-05-30 14:13:18 +02:00
committed by GitHub
parent 5a8899c4c9
commit b8ab4b6a5e
7 changed files with 408 additions and 66 deletions

View File

@@ -25,6 +25,7 @@ import { getTriggerNodeServiceName } from '@/utils/nodeTypesUtils';
import { useExternalHooks } from '@/composables/useExternalHooks';
import { useNodeHelpers } from '@/composables/useNodeHelpers';
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
import { useRunWorkflow } from '@/composables/useRunWorkflow';
export type SimplifiedExecution = Pick<
IExecutionResponse,
@@ -94,34 +95,6 @@ export async function executionFinished(
}
}
// Implicit looping: This will re-trigger the evaluation trigger if it exists on a successful execution of the workflow.
if (execution.status === 'success' && execution.data?.startData?.destinationNode === undefined) {
// check if we have an evaluation trigger in our workflow and whether it has any run data
const evalTrigger = execution.workflowData.nodes.find(
(node) => node.type === EVALUATION_TRIGGER_NODE_TYPE,
);
const triggerRunData = evalTrigger
? execution?.data?.resultData?.runData[evalTrigger.name]
: undefined;
if (evalTrigger && triggerRunData !== undefined) {
const mainData = triggerRunData[0]?.data?.main[0];
const rowsLeft = mainData ? (mainData[0]?.json?._rowsLeft as number) : 0;
if (rowsLeft && rowsLeft > 0) {
// Find the button that belongs to the evaluation trigger, and click it.
const testId = `execute-workflow-button-${evalTrigger.name}`;
setTimeout(() => {
const button = Array.from(document.querySelectorAll('[data-test-id]')).filter((x) =>
(x as HTMLElement)?.dataset?.testId?.startsWith(testId),
)[0];
(button as HTMLElement)?.click();
}, 2);
}
}
}
const runExecutionData = getRunExecutionData(execution);
uiStore.setProcessingExecutionResults(false);
@@ -134,6 +107,47 @@ export async function executionFinished(
}
setRunExecutionData(execution, runExecutionData);
continueEvaluationLoop(execution, options.router);
}
/**
* Implicit looping: This will re-trigger the evaluation trigger if it exists on a successful execution of the workflow.
* @param execution
* @param router
*/
export function continueEvaluationLoop(
execution: SimplifiedExecution,
router: ReturnType<typeof useRouter>,
) {
if (execution.status !== 'success' || execution.data?.startData?.destinationNode !== undefined) {
return;
}
// check if we have an evaluation trigger in our workflow and whether it has any run data
const evaluationTrigger = execution.workflowData.nodes.find(
(node) => node.type === EVALUATION_TRIGGER_NODE_TYPE,
);
const triggerRunData = evaluationTrigger
? execution?.data?.resultData?.runData[evaluationTrigger.name]
: undefined;
if (!evaluationTrigger || triggerRunData === undefined) {
return;
}
const mainData = triggerRunData[0]?.data?.main[0];
const rowsLeft = mainData ? (mainData[0]?.json?._rowsLeft as number) : 0;
if (rowsLeft && rowsLeft > 0) {
const { runWorkflow } = useRunWorkflow({ router });
void runWorkflow({
triggerNode: evaluationTrigger.name,
// pass output of previous node run to trigger next run
nodeData: triggerRunData[0],
rerunTriggerNode: true,
});
}
}
/**