From deaa015e61899bd82e7db4fe32ffe11940f2430b Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Sat, 13 Feb 2021 20:40:27 +0100 Subject: [PATCH] :zap: Do only send manual executions to starting session & cleanup --- packages/cli/src/Interfaces.ts | 6 +- packages/cli/src/Server.ts | 4 +- .../cli/src/WorkflowExecuteAdditionalData.ts | 93 +++++++++---------- packages/cli/src/WorkflowRunner.ts | 9 +- packages/editor-ui/src/Interface.ts | 9 +- .../src/components/ExecutionsList.vue | 5 +- .../src/components/mixins/pushConnection.ts | 4 +- packages/editor-ui/src/store.ts | 8 +- packages/editor-ui/src/views/NodeView.vue | 5 +- 9 files changed, 61 insertions(+), 82 deletions(-) diff --git a/packages/cli/src/Interfaces.ts b/packages/cli/src/Interfaces.ts index 8253d3c396..d5f8f1af3c 100644 --- a/packages/cli/src/Interfaces.ts +++ b/packages/cli/src/Interfaces.ts @@ -179,8 +179,7 @@ export interface IExecutionsStopData { } export interface IExecutionsSummary { - id?: string; // executionIdDb - idActive?: string; // executionIdActive + id: string; finished?: boolean; mode: WorkflowExecuteMode; retryOf?: string; @@ -327,8 +326,7 @@ export type IPushDataType = 'executionFinished' | 'executionStarted' | 'nodeExec export interface IPushDataExecutionFinished { data: IRun; - executionIdActive: string; - executionIdDb?: string; + executionId: string; retryOf?: string; } diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index c52e2f66bc..aed8de09a0 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -1670,7 +1670,7 @@ class App { return results.map(result => { return { - idActive: result.id, + id: result.id, workflowId: result.workflowId, mode: result.mode, retryOf: result.retryOf !== null ? result.retryOf : undefined, @@ -1693,7 +1693,7 @@ class App { } returnData.push( { - idActive: data.id.toString(), + id: data.id.toString(), workflowId: data.workflowId === undefined ? '' : data.workflowId.toString(), mode: data.mode, retryOf: data.retryOf, diff --git a/packages/cli/src/WorkflowExecuteAdditionalData.ts b/packages/cli/src/WorkflowExecuteAdditionalData.ts index 2ef00c0473..2d0855bcbd 100644 --- a/packages/cli/src/WorkflowExecuteAdditionalData.ts +++ b/packages/cli/src/WorkflowExecuteAdditionalData.ts @@ -117,42 +117,6 @@ function pruneExecutionData(): void { } -/** - * Pushes the execution out to all connected clients - * - * @param {WorkflowExecuteMode} mode The mode in which the workflow got started in - * @param {IRun} fullRunData The RunData of the finished execution - * @param {string} executionIdActive The id of the finished execution - * @param {string} [executionIdDb] The database id of finished execution - */ -export function pushExecutionFinished(mode: WorkflowExecuteMode, fullRunData: IRun, executionIdActive: string, executionIdDb?: string, retryOf?: string) { - // Clone the object except the runData. That one is not supposed - // to be send. Because that data got send piece by piece after - // each node which finished executing - const pushRunData = { - ...fullRunData, - data: { - ...fullRunData.data, - resultData: { - ...fullRunData.data.resultData, - runData: {}, - }, - }, - }; - - // Push data to editor-ui once workflow finished - const sendData: IPushDataExecutionFinished = { - executionIdActive, - executionIdDb, - data: pushRunData, - retryOf, - }; - - const pushInstance = Push.getInstance(); - pushInstance.send('executionFinished', sendData); -} - - /** * Returns hook functions to push data to Editor-UI * @@ -192,25 +156,52 @@ function hookFunctionsPush(): IWorkflowExecuteHooks { ], workflowExecuteBefore: [ async function (this: WorkflowHooks): Promise { - // Push data to editor-ui once workflow finished - if (this.mode === 'manual') { - const pushInstance = Push.getInstance(); - pushInstance.send('executionStarted', { - executionId: this.executionId, - mode: this.mode, - startedAt: new Date(), - retryOf: this.retryOf, - workflowId: this.workflowData.id as string, - workflowName: this.workflowData.name, - }); + // Push data to session which started the workflow + if (this.sessionId === undefined) { + return; } + const pushInstance = Push.getInstance(); + pushInstance.send('executionStarted', { + executionId: this.executionId, + mode: this.mode, + startedAt: new Date(), + retryOf: this.retryOf, + workflowId: this.workflowData.id as string, + workflowName: this.workflowData.name, + }, this.sessionId); }, ], workflowExecuteAfter: [ async function (this: WorkflowHooks, fullRunData: IRun, newStaticData: IDataObject): Promise { - if (this.mode === 'manual') { - pushExecutionFinished(this.mode, fullRunData, this.executionId, undefined, this.retryOf); + // Push data to session which started the workflow + if (this.sessionId === undefined) { + return; } + + // Clone the object except the runData. That one is not supposed + // to be send. Because that data got send piece by piece after + // each node which finished executing + const pushRunData = { + ...fullRunData, + data: { + ...fullRunData.data, + resultData: { + ...fullRunData.data.resultData, + runData: {}, + }, + }, + }; + + // Push data to editor-ui once workflow finished + // TODO: Look at this again + const sendData: IPushDataExecutionFinished = { + executionId: this.executionId, + data: pushRunData, + retryOf: this.retryOf, + }; + + const pushInstance = Push.getInstance(); + pushInstance.send('executionFinished', sendData, this.sessionId); }, ], }; @@ -243,7 +234,7 @@ export function hookFunctionsPreExecute(parentProcessMode?: string): IWorkflowEx if (execution === undefined) { // Something went badly wrong if this happens. // This check is here mostly to make typescript happy. - return undefined; + return undefined; } const fullExecutionData: IExecutionResponse = ResponseHelper.unflattenExecutionData(execution); @@ -282,7 +273,7 @@ export function hookFunctionsPreExecute(parentProcessMode?: string): IWorkflowEx // Set last executed node so that it may resume on failure fullExecutionData.data.resultData.lastNodeExecuted = nodeName; - + const flattenedExecutionData = ResponseHelper.flattenExecutionData(fullExecutionData); await Db.collections.Execution!.update(this.executionId, flattenedExecutionData as IExecutionFlattedDb); diff --git a/packages/cli/src/WorkflowRunner.ts b/packages/cli/src/WorkflowRunner.ts index 5338a4a46d..e382ac2827 100644 --- a/packages/cli/src/WorkflowRunner.ts +++ b/packages/cli/src/WorkflowRunner.ts @@ -101,9 +101,6 @@ export class WorkflowRunner { // Remove from active execution with empty data. That will // set the execution to failed. this.activeExecutions.remove(executionId, fullRunData); - - // Also send to Editor UI - WorkflowExecuteAdditionalData.pushExecutionFinished(executionMode, fullRunData, executionId); } /** @@ -175,7 +172,7 @@ export class WorkflowRunner { workflowExecution = workflowExecute.processRunExecutionData(workflow); } else if (data.runData === undefined || data.startNodes === undefined || data.startNodes.length === 0 || data.destinationNode === undefined) { // Execute all nodes - + // Can execute without webhook so go on const workflowExecute = new WorkflowExecute(additionalData, data.executionMode); workflowExecution = workflowExecute.run(workflow, undefined, data.destinationNode); @@ -298,7 +295,7 @@ export class WorkflowRunner { }, queueRecoveryInterval * 1000); }); - + const clearWatchdogInterval = () => { if (watchDogInterval) { clearInterval(watchDogInterval); @@ -332,7 +329,7 @@ export class WorkflowRunner { await jobData; } - + const executionDb = await Db.collections.Execution!.findOne(executionId) as IExecutionFlattedDb; const fullExecutionData = ResponseHelper.unflattenExecutionData(executionDb) as IExecutionResponse; diff --git a/packages/editor-ui/src/Interface.ts b/packages/editor-ui/src/Interface.ts index b4a5e248ca..972ef0cbd8 100644 --- a/packages/editor-ui/src/Interface.ts +++ b/packages/editor-ui/src/Interface.ts @@ -314,8 +314,7 @@ export interface IExecutionsListResponse { } export interface IExecutionsCurrentSummaryExtended { - id?: string; - idActive: string; + id: string; finished?: boolean; mode: WorkflowExecuteMode; retryOf?: string; @@ -334,8 +333,7 @@ export interface IExecutionsStopData { } export interface IExecutionsSummary { - id?: string; // executionIdDb - idActive?: string; // executionIdActive + id: string; mode: WorkflowExecuteMode; finished?: boolean; retryOf?: string; @@ -370,8 +368,7 @@ export interface IPushDataExecutionStarted { export interface IPushDataExecutionFinished { data: IRun; - executionIdActive: string; - executionIdDb?: string; + executionId: string; retryOf?: string; } diff --git a/packages/editor-ui/src/components/ExecutionsList.vue b/packages/editor-ui/src/components/ExecutionsList.vue index 806fcd5853..e07b018981 100644 --- a/packages/editor-ui/src/components/ExecutionsList.vue +++ b/packages/editor-ui/src/components/ExecutionsList.vue @@ -57,7 +57,6 @@ @@ -126,8 +125,8 @@