From 7a4acb9398a1ce762c19d61da623edc2a044ac4a Mon Sep 17 00:00:00 2001 From: Ben White Date: Fri, 28 Jun 2024 16:55:29 +0200 Subject: [PATCH] fix(cdp): Invocation loop (#23331) --- plugin-server/src/cdp/cdp-consumers.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/plugin-server/src/cdp/cdp-consumers.ts b/plugin-server/src/cdp/cdp-consumers.ts index a1f731890b5af..c56671061a2e9 100644 --- a/plugin-server/src/cdp/cdp-consumers.ts +++ b/plugin-server/src/cdp/cdp-consumers.ts @@ -546,17 +546,20 @@ export class CdpOverflowConsumer extends CdpConsumerBase { return await runInstrumentedFunction({ statsKey: `cdpConsumer.handleEachBatch.executeOverflowedFunctions`, func: async () => { - const results = ( - await Promise.all( - invocationGlobals.map((item) => { - return this.runManyWithHeartbeat(item.hogFunctionIds, (hogFunctionId) => - this.hogExecutor.executeFunction(item.globals, hogFunctionId) - ) - }) + const invocations = invocationGlobals + .map((item) => + item.hogFunctionIds.map((hogFunctionId) => ({ + globals: item.globals, + hogFunctionId, + })) ) - ) .flat() - .filter((x) => !!x) as HogFunctionInvocationResult[] + + const results = ( + await this.runManyWithHeartbeat(invocations, (item) => + this.hogExecutor.executeFunction(item.globals, item.hogFunctionId) + ) + ).filter((x) => !!x) as HogFunctionInvocationResult[] this.hogWatcher.currentObservations.observeResults(results) return results