cleanup, still hacky

This commit is contained in:
Charlie Kolb 2024-10-30 17:42:17 +01:00
parent 6a1eb06fb7
commit 105b5fe6e4
No known key found for this signature in database
2 changed files with 10 additions and 29 deletions

View file

@ -141,10 +141,9 @@ export class WorkflowRunner {
if (this.executionsMode === 'queue' && data.executionMode !== 'manual') { if (this.executionsMode === 'queue' && data.executionMode !== 'manual') {
// Do not run "manual" executions in bull because sending events to the // Do not run "manual" executions in bull because sending events to the
// frontend would not be possible // frontend would not be possible
console.log('X');
await this.enqueueExecution(executionId, data, loadStaticData, realtime); await this.enqueueExecution(executionId, data, loadStaticData, realtime);
} else { } else {
console.log('Y'); // Relevant path
await this.runMainProcess(executionId, data, loadStaticData, restartExecutionId); await this.runMainProcess(executionId, data, loadStaticData, restartExecutionId);
this.eventService.emit('workflow-pre-execute', { executionId, data }); this.eventService.emit('workflow-pre-execute', { executionId, data });
} }
@ -264,7 +263,6 @@ export class WorkflowRunner {
additionalData.sendDataToUI = WorkflowExecuteAdditionalData.sendDataToUI.bind({ additionalData.sendDataToUI = WorkflowExecuteAdditionalData.sendDataToUI.bind({
pushRef: data.pushRef, pushRef: data.pushRef,
}); });
console.log('startNodes', data.startNodes);
if (data.executionData !== undefined) { if (data.executionData !== undefined) {
this.logger.debug(`Execution ID ${executionId} had Execution data. Running with payload.`, { this.logger.debug(`Execution ID ${executionId} had Execution data. Running with payload.`, {
executionId, executionId,
@ -280,14 +278,16 @@ export class WorkflowRunner {
data.startNodes === undefined || data.startNodes === undefined ||
data.startNodes.length === 0 data.startNodes.length === 0
) { ) {
// We end up here due to runData being undefined
// (defining runData broke things in the front end, likely due to my own ignorance)
// Full Execution // Full Execution
this.logger.debug(`Execution ID ${executionId} will run executing all nodes.`, { this.logger.debug(`Execution ID ${executionId} will run executing all nodes.`, {
executionId, executionId,
}); });
// Execute all nodes // Execute all nodes
// This only allows startNodes with pinned data before our changes
const startNode = WorkflowHelpers.getExecutionStartNode(data, workflow); const startNode = WorkflowHelpers.getExecutionStartNode(data, workflow);
console.log('startNode', startNode);
// Can execute without webhook so go on // Can execute without webhook so go on
const workflowExecute = new WorkflowExecute(additionalData, data.executionMode); const workflowExecute = new WorkflowExecute(additionalData, data.executionMode);
workflowExecution = workflowExecute.run( workflowExecution = workflowExecute.run(

View file

@ -101,13 +101,14 @@ export class WorkflowExecutionService {
partialExecutionVersion?: string, partialExecutionVersion?: string,
) { ) {
const pinData = workflowData.pinData; const pinData = workflowData.pinData;
// Webhook is broken with this hacked setup
const pinnedTrigger = preferredTrigger const pinnedTrigger = preferredTrigger
? workflowData.nodes.find((n) => n.name === preferredTrigger) ? workflowData.nodes.find((n) => n.name === preferredTrigger)
: this.selectPinnedActivatorStarter( : this.selectPinnedActivatorStarter(
workflowData, workflowData,
startNodes?.map((nodeData) => nodeData.name), startNodes?.map((nodeData) => nodeData.name),
pinData, pinData,
preferredTrigger,
); );
console.log('pinnedTrigger', pinnedTrigger); console.log('pinnedTrigger', pinnedTrigger);
// If webhooks nodes exist and are active we have to wait for till we receive a call // If webhooks nodes exist and are active we have to wait for till we receive a call
@ -153,8 +154,6 @@ export class WorkflowExecutionService {
if (pinnedTrigger && !hasRunData(pinnedTrigger)) { if (pinnedTrigger && !hasRunData(pinnedTrigger)) {
data.startNodes = [{ name: pinnedTrigger.name, sourceData: null }]; data.startNodes = [{ name: pinnedTrigger.name, sourceData: null }];
} }
// eslint-disable-next-line n8n-local-rules/no-plain-errors
// throw new Error(`${pinnedTrigger?.name}`);
const executionId = await this.workflowRunner.run(data); const executionId = await this.workflowRunner.run(data);
@ -314,35 +313,21 @@ export class WorkflowExecutionService {
* prioritizing `n8n-nodes-base.webhook` over other activators. If the executed node * prioritizing `n8n-nodes-base.webhook` over other activators. If the executed node
* has no upstream nodes and is itself is a pinned activator, select it. * has no upstream nodes and is itself is a pinned activator, select it.
*/ */
selectPinnedActivatorStarter( selectPinnedActivatorStarter(workflow: IWorkflowDb, startNodes?: string[], pinData?: IPinData) {
workflow: IWorkflowDb,
startNodes?: string[],
pinData?: IPinData,
preferredTrigger?: string,
) {
if (!pinData || !startNodes) return null; if (!pinData || !startNodes) return null;
const allPinnedActivators = this.findAllPinnedActivators(workflow, pinData); const allPinnedActivators = this.findAllPinnedActivators(workflow, pinData);
console.log('A', preferredTrigger);
console.log('all', JSON.stringify(allPinnedActivators));
if (allPinnedActivators.length === 0) return null; if (allPinnedActivators.length === 0) return null;
if (allPinnedActivators.find((pa) => pa.name === preferredTrigger)) {
return allPinnedActivators.find((pa) => pa.name === preferredTrigger);
}
console.log('B');
let [firstPinnedActivator] = allPinnedActivators; const [firstPinnedActivator] = allPinnedActivators;
// full manual execution // full manual execution
if (startNodes?.length === 0) return firstPinnedActivator ?? null; if (startNodes?.length === 0) return firstPinnedActivator ?? null;
// partial manual execution // partial manual execution
const dbg = [];
const [preferredActivator] = allPinnedActivators.filter((pa) => pa.name === preferredTrigger);
firstPinnedActivator = preferredActivator ?? firstPinnedActivator;
dbg.push(firstPinnedActivator.name);
/** /**
* If the partial manual execution has 2+ start nodes, we search only the zeroth * If the partial manual execution has 2+ start nodes, we search only the zeroth
* start node's parents for a pinned activator. If we had 2+ start nodes without * start node's parents for a pinned activator. If we had 2+ start nodes without
@ -359,14 +344,10 @@ export class WorkflowExecutionService {
}).getParentNodes(firstStartNodeName); }).getParentNodes(firstStartNodeName);
if (parentNodeNames.length > 0) { if (parentNodeNames.length > 0) {
const parentNodeName = const parentNodeName = parentNodeNames.find((p) => p === firstPinnedActivator.name);
parentNodeNames.find((p) => p === preferredTrigger) ??
parentNodeNames.find((p) => p === firstPinnedActivator.name);
dbg.push('A');
return allPinnedActivators.find((pa) => pa.name === parentNodeName) ?? null; return allPinnedActivators.find((pa) => pa.name === parentNodeName) ?? null;
} }
dbg.push('B');
return allPinnedActivators.find((pa) => pa.name === firstStartNodeName) ?? null; return allPinnedActivators.find((pa) => pa.name === firstStartNodeName) ?? null;
} }