From af55ecd64b1d4948fc08d7d32900fa9d57ef299b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Wed, 11 Jan 2023 10:52:32 +0100 Subject: [PATCH] fix(editor): Recover from unsaved finished execution (#5121) * :bug: Recover from unsaved fixed execution * :fire: Remove logging * :pencil2: Use i18n --- packages/editor-ui/src/Interface.ts | 5 ++++ .../src/plugins/i18n/locales/en.json | 2 ++ packages/editor-ui/src/stores/workflows.ts | 5 +++- packages/editor-ui/src/views/NodeView.vue | 23 ++++++++++++++++++- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/packages/editor-ui/src/Interface.ts b/packages/editor-ui/src/Interface.ts index 3cc4618bc0013..f8828dd670fc7 100644 --- a/packages/editor-ui/src/Interface.ts +++ b/packages/editor-ui/src/Interface.ts @@ -544,6 +544,11 @@ export interface IPushDataExecutionFinished { retryOf?: string; } +export interface IPushDataUnsavedExecutionFinished { + executionId: string; + data: { finished: true; stoppedAt: Date }; +} + export interface IPushDataExecutionStarted { executionId: string; } diff --git a/packages/editor-ui/src/plugins/i18n/locales/en.json b/packages/editor-ui/src/plugins/i18n/locales/en.json index c58d0f5e44792..d91a644b3af09 100644 --- a/packages/editor-ui/src/plugins/i18n/locales/en.json +++ b/packages/editor-ui/src/plugins/i18n/locales/en.json @@ -820,6 +820,8 @@ "nodeView.showMessage.keyDown.title": "Workflow created", "nodeView.showMessage.showMaxNodeTypeError.message": "Only one '{nodeTypeDataDisplayName}' node is allowed in a workflow | Only {count} '{nodeTypeDataDisplayName}' nodes are allowed in a workflow", "nodeView.showMessage.showMaxNodeTypeError.title": "Could not insert node", + "nodeView.showMessage.stopExecutionCatch.unsaved.message": "This execution was canceled", + "nodeView.showMessage.stopExecutionCatch.unsaved.title": "Execution canceled", "nodeView.showMessage.stopExecutionCatch.message": "It completed before it could be stopped", "nodeView.showMessage.stopExecutionCatch.title": "Workflow finished executing", "nodeView.showMessage.stopExecutionTry.title": "Execution stopped", diff --git a/packages/editor-ui/src/stores/workflows.ts b/packages/editor-ui/src/stores/workflows.ts index b62c37e02b086..f56ca4db63d0d 100644 --- a/packages/editor-ui/src/stores/workflows.ts +++ b/packages/editor-ui/src/stores/workflows.ts @@ -15,6 +15,7 @@ import { INodeUpdatePropertiesInformation, IPushDataExecutionFinished, IPushDataNodeExecuteAfter, + IPushDataUnsavedExecutionFinished, IUpdateInformation, IUsedCredential, IWorkflowDb, @@ -886,7 +887,9 @@ export const useWorkflowsStore = defineStore(STORES.WORKFLOWS, { } this.activeExecutions.unshift(newActiveExecution); }, - finishActiveExecution(finishedActiveExecution: IPushDataExecutionFinished): void { + finishActiveExecution( + finishedActiveExecution: IPushDataExecutionFinished | IPushDataUnsavedExecutionFinished, + ): void { // Find the execution to set to finished const activeExecution = this.activeExecutions.find((execution) => { return execution.id === finishedActiveExecution.executionId; diff --git a/packages/editor-ui/src/views/NodeView.vue b/packages/editor-ui/src/views/NodeView.vue index 07f0238144c08..a5a7cfb50ebd6 100644 --- a/packages/editor-ui/src/views/NodeView.vue +++ b/packages/editor-ui/src/views/NodeView.vue @@ -1383,7 +1383,28 @@ export default mixins( } catch (error) { // Execution stop might fail when the execution has already finished. Let's treat this here. const execution = await this.restApi().getExecution(executionId); - if (execution?.finished) { + + if (execution === undefined) { + // execution finished but was not saved (e.g. due to low connectivity) + + this.workflowsStore.finishActiveExecution({ + executionId, + data: { finished: true, stoppedAt: new Date() }, + }); + this.workflowsStore.executingNode = null; + this.uiStore.removeActiveAction('workflowRunning'); + + this.$titleSet(this.workflowsStore.workflowName, 'IDLE'); + this.$showMessage({ + title: this.$locale.baseText('nodeView.showMessage.stopExecutionCatch.unsaved.title'), + message: this.$locale.baseText( + 'nodeView.showMessage.stopExecutionCatch.unsaved.message', + ), + type: 'success', + }); + } else if (execution?.finished) { + // execution finished before it could be stopped + const executedData = { data: execution.data, finished: execution.finished,