From 4786aafddcec8cdbb7c55c7fd961881e40236bac Mon Sep 17 00:00:00 2001 From: Henry Heng Date: Fri, 16 May 2025 15:32:21 +0800 Subject: [PATCH] Bugfix/execute custom function to worker (#4440) * pass execute custom function to worker * update execute function --- packages/server/src/queue/PredictionQueue.ts | 3 ++- packages/server/src/utils/executeCustomNodeFunction.ts | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/server/src/queue/PredictionQueue.ts b/packages/server/src/queue/PredictionQueue.ts index 46092d657..2b5575712 100644 --- a/packages/server/src/queue/PredictionQueue.ts +++ b/packages/server/src/queue/PredictionQueue.ts @@ -77,11 +77,12 @@ export class PredictionQueue extends BaseQueue { } if (Object.prototype.hasOwnProperty.call(data, 'isExecuteCustomFunction')) { + const executeCustomFunctionData = data as any logger.info(`Executing Custom Function...`) return await executeCustomNodeFunction({ appDataSource: this.appDataSource, componentNodes: this.componentNodes, - data + data: executeCustomFunctionData.data }) } diff --git a/packages/server/src/utils/executeCustomNodeFunction.ts b/packages/server/src/utils/executeCustomNodeFunction.ts index 1695cc17c..a22a0291a 100644 --- a/packages/server/src/utils/executeCustomNodeFunction.ts +++ b/packages/server/src/utils/executeCustomNodeFunction.ts @@ -17,9 +17,10 @@ export const executeCustomNodeFunction = async ({ }) => { try { const body = data - const functionInputVariables = Object.fromEntries( - [...(body?.javascriptFunction ?? '').matchAll(/\$([a-zA-Z0-9_]+)/g)].map((g) => [g[1], undefined]) - ) + const jsFunction = typeof body?.javascriptFunction === 'string' ? body.javascriptFunction : '' + const matches = jsFunction.matchAll(/\$([a-zA-Z0-9_]+)/g) + const matchesArray: RegExpMatchArray[] = Array.from(matches) + const functionInputVariables = Object.fromEntries(matchesArray.map((g) => [g[1], undefined])) if (functionInputVariables && Object.keys(functionInputVariables).length) { for (const key in functionInputVariables) { if (key.includes('vars')) {