From 8b567c20b9f881db10e677561cfaa99b0a2969dd Mon Sep 17 00:00:00 2001 From: lublak <44057030+lublak@users.noreply.github.com> Date: Sat, 12 Dec 2020 18:36:47 +0100 Subject: [PATCH] :zap: Allow workflow to trigger on own error trigger (#1205) * allow workflow to trigger on own error trigger * use config errorTriggerType instance of a static string * don't trigger twice --- packages/cli/src/WorkflowExecuteAdditionalData.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/WorkflowExecuteAdditionalData.ts b/packages/cli/src/WorkflowExecuteAdditionalData.ts index cf755a6eaa..3d851db10b 100644 --- a/packages/cli/src/WorkflowExecuteAdditionalData.ts +++ b/packages/cli/src/WorkflowExecuteAdditionalData.ts @@ -43,9 +43,11 @@ import * as config from '../config'; import { LessThanOrEqual } from "typeorm"; +const ERROR_TRIGGER_TYPE = config.get('nodes.errorTriggerType') as string; + /** - * Checks if there was an error and if errorWorkflow is defined. If so it collects + * Checks if there was an error and if errorWorkflow or a trigger is defined. If so it collects * all the data and executes it * * @param {IWorkflowBase} workflowData The workflow which got executed @@ -54,14 +56,14 @@ import { LessThanOrEqual } from "typeorm"; * @param {string} [executionId] The id the execution got saved as */ function executeErrorWorkflow(workflowData: IWorkflowBase, fullRunData: IRun, mode: WorkflowExecuteMode, executionId?: string, retryOf?: string): void { - // Check if there was an error and if so if an errorWorkflow is set + // Check if there was an error and if so if an errorWorkflow or a trigger is set let pastExecutionUrl: string | undefined = undefined; if (executionId !== undefined) { pastExecutionUrl = `${WebhookHelpers.getWebhookBaseUrl()}execution/${executionId}`; } - if (fullRunData.data.resultData.error !== undefined && workflowData.settings !== undefined && workflowData.settings.errorWorkflow) { + if (fullRunData.data.resultData.error !== undefined) { const workflowErrorData = { execution: { id: executionId, @@ -77,7 +79,12 @@ function executeErrorWorkflow(workflowData: IWorkflowBase, fullRunData: IRun, mo }, }; // Run the error workflow - WorkflowHelpers.executeErrorWorkflow(workflowData.settings.errorWorkflow as string, workflowErrorData); + if(workflowData.id !== undefined && workflowData.nodes.some((node) => node.type === ERROR_TRIGGER_TYPE)) { + WorkflowHelpers.executeErrorWorkflow(workflowData.id.toString(), workflowErrorData); + } + if(workflowData.settings !== undefined && workflowData.settings.errorWorkflow && workflowData.settings.errorWorkflow != workflowData.id) { + WorkflowHelpers.executeErrorWorkflow(workflowData.settings.errorWorkflow as string, workflowErrorData); + } } }