refactor(core): Move execution engine code out of n8n-workflow (no-changelog) (#12147)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-12-12 13:54:44 +01:00
committed by GitHub
parent 73f0c4cca9
commit 5a055ed526
44 changed files with 1995 additions and 1795 deletions

View File

@@ -1,10 +1,8 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import {
ActiveWorkflows,
ErrorReporter,
InstanceSettings,
NodeExecuteFunctions,
PollContext,
TriggerContext,
} from 'n8n-core';
@@ -186,12 +184,7 @@ export class ActiveWorkflowManager {
try {
// TODO: this should happen in a transaction, that way we don't need to manually remove this in `catch`
await this.webhookService.storeWebhook(webhook);
await workflow.createWebhookIfNotExists(
webhookData,
NodeExecuteFunctions,
mode,
activation,
);
await this.webhookService.createWebhookIfNotExists(workflow, webhookData, mode, activation);
} catch (error) {
if (activation === 'init' && error.name === 'QueryFailedError') {
// n8n does not remove the registered webhooks on exit.
@@ -261,7 +254,7 @@ export class ActiveWorkflowManager {
const webhooks = WebhookHelpers.getWorkflowWebhooks(workflow, additionalData, undefined, true);
for (const webhookData of webhooks) {
await workflow.deleteWebhook(webhookData, NodeExecuteFunctions, mode, 'update');
await this.webhookService.deleteWebhook(workflow, webhookData, mode, 'update');
}
await this.workflowStaticDataService.saveStaticData(workflow);
@@ -557,7 +550,7 @@ export class ActiveWorkflowManager {
settings: dbWorkflow.settings,
});
const canBeActivated = workflow.checkIfWorkflowCanBeActivated(STARTING_NODES);
const canBeActivated = this.checkIfWorkflowCanBeActivated(workflow, STARTING_NODES);
if (!canBeActivated) {
throw new WorkflowActivationError(
@@ -601,6 +594,48 @@ export class ActiveWorkflowManager {
return shouldDisplayActivationMessage;
}
/**
* A workflow can only be activated if it has a node which has either triggers
* or webhooks defined.
*
* @param {string[]} [ignoreNodeTypes] Node-types to ignore in the check
*/
checkIfWorkflowCanBeActivated(workflow: Workflow, ignoreNodeTypes?: string[]): boolean {
let node: INode;
let nodeType: INodeType | undefined;
for (const nodeName of Object.keys(workflow.nodes)) {
node = workflow.nodes[nodeName];
if (node.disabled === true) {
// Deactivated nodes can not trigger a run so ignore
continue;
}
if (ignoreNodeTypes !== undefined && ignoreNodeTypes.includes(node.type)) {
continue;
}
nodeType = this.nodeTypes.getByNameAndVersion(node.type, node.typeVersion);
if (nodeType === undefined) {
// Type is not known so check is not possible
continue;
}
if (
nodeType.poll !== undefined ||
nodeType.trigger !== undefined ||
nodeType.webhook !== undefined
) {
// Is a trigger node. So workflow can be activated.
return true;
}
}
return false;
}
/**
* Count all triggers in the workflow, excluding Manual Trigger.
*/