refactor(editor): Refactor usePushConnection and introduce new queueing system (#14529)

This commit is contained in:
Alex Grozav
2025-04-30 15:36:43 +03:00
committed by GitHub
parent 442cd094ee
commit 833d8e3c18
49 changed files with 1525 additions and 1262 deletions

View File

@@ -16,8 +16,8 @@ import type {
IDataObject,
IWorkflowBase,
} from 'n8n-workflow';
import { NodeConnectionTypes, TelemetryHelpers } from 'n8n-workflow';
import { retry } from '@n8n/utils/retry';
import { useToast } from '@/composables/useToast';
import { useNodeHelpers } from '@/composables/useNodeHelpers';
@@ -29,7 +29,6 @@ import {
} from '@/constants';
import { useRootStore } from '@/stores/root.store';
import { useUIStore } from '@/stores/ui.store';
import { useWorkflowsStore } from '@/stores/workflows.store';
import { displayForm } from '@/utils/executionUtils';
import { useExternalHooks } from '@/composables/useExternalHooks';
@@ -55,7 +54,6 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
const rootStore = useRootStore();
const pushConnectionStore = usePushConnectionStore();
const uiStore = useUIStore();
const workflowsStore = useWorkflowsStore();
const executionsStore = useExecutionsStore();
const { dirtinessByName } = useNodeDirtiness();
@@ -70,26 +68,25 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
workflowsStore.subWorkflowExecutionError = null;
uiStore.addActiveAction('workflowRunning');
// Set the execution as started, but still waiting for the execution to be retrieved
workflowsStore.setActiveExecutionId(null);
let response: IExecutionPushResponse;
try {
response = await workflowsStore.runWorkflow(runData);
} catch (error) {
uiStore.removeActiveAction('workflowRunning');
workflowsStore.setActiveExecutionId(undefined);
throw error;
}
if (
response.executionId !== undefined &&
workflowsStore.previousExecutionId !== response.executionId
) {
const workflowExecutionIdIsNew = workflowsStore.previousExecutionId !== response.executionId;
const workflowExecutionIdIsPending = workflowsStore.activeExecutionId === null;
if (response.executionId && workflowExecutionIdIsNew && workflowExecutionIdIsPending) {
workflowsStore.setActiveExecutionId(response.executionId);
}
if (response.waitingForWebhook === true && useWorkflowsStore().nodesIssuesExist) {
uiStore.removeActiveAction('workflowRunning');
if (response.waitingForWebhook === true && workflowsStore.nodesIssuesExist) {
workflowsStore.setActiveExecutionId(undefined);
throw new Error(i18n.baseText('workflowRun.showError.resolveOutstandingIssues'));
}
@@ -106,12 +103,12 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
nodeData?: ITaskData;
source?: string;
}): Promise<IExecutionPushResponse | undefined> {
const workflow = workflowHelpers.getCurrentWorkflow();
if (uiStore.isActionActive.workflowRunning) {
if (workflowsStore.activeExecutionId) {
return;
}
const workflow = workflowHelpers.getCurrentWorkflow();
toast.clearAllStickyNotifications();
try {
@@ -417,7 +414,7 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
async function stopCurrentExecution() {
const executionId = workflowsStore.activeExecutionId;
if (executionId === null) {
if (!executionId) {
return;
}
@@ -455,15 +452,18 @@ export function useRunWorkflow(useRunWorkflowOpts: { router: ReturnType<typeof u
}
} finally {
// Wait for websocket event to update the execution status to 'canceled'
for (let i = 0; i < 100; i++) {
if (workflowsStore.workflowExecutionData?.status !== 'running') {
break;
}
await retry(
async () => {
if (workflowsStore.workflowExecutionData?.status !== 'running') {
workflowsStore.markExecutionAsStopped();
return true;
}
await new Promise(requestAnimationFrame);
}
workflowsStore.markExecutionAsStopped();
return false;
},
250,
10,
);
}
}