mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 21:37:32 -08:00
fix(core): Filter out workflows that failed to activate on startup (#6676)
* fix(core): Deactivate on init workflow that should not be retried * fix(core): Filter out workflows with activation errors
This commit is contained in:
parent
92192fbd61
commit
667c15d0df
1
.vscode/launch.json
vendored
1
.vscode/launch.json
vendored
|
@ -26,6 +26,7 @@
|
||||||
"name": "Launch n8n with debug",
|
"name": "Launch n8n with debug",
|
||||||
"program": "${workspaceFolder}/packages/cli/bin/n8n",
|
"program": "${workspaceFolder}/packages/cli/bin/n8n",
|
||||||
"cwd": "${workspaceFolder}/packages/cli/bin",
|
"cwd": "${workspaceFolder}/packages/cli/bin",
|
||||||
|
// "args": ["start", "--tunnel"],
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"skipFiles": ["<node_internals>/**"],
|
"skipFiles": ["<node_internals>/**"],
|
||||||
"type": "node",
|
"type": "node",
|
||||||
|
|
|
@ -134,7 +134,7 @@ export class ActiveWorkflowRunner {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
ErrorReporter.error(error);
|
ErrorReporter.error(error);
|
||||||
Logger.info(
|
Logger.info(
|
||||||
' => ERROR: Workflow could not be activated on first try, keep on trying',
|
' => ERROR: Workflow could not be activated on first try, keep on trying if not an auth issue',
|
||||||
);
|
);
|
||||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||||
Logger.info(` ${error.message}`);
|
Logger.info(` ${error.message}`);
|
||||||
|
@ -148,10 +148,12 @@ export class ActiveWorkflowRunner {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||||
this.executeErrorWorkflow(error, workflowData, 'internal');
|
this.executeErrorWorkflow(error, workflowData, 'internal');
|
||||||
|
|
||||||
// Keep on trying to activate the workflow
|
if (!error.message.includes('Authorization')) {
|
||||||
|
// Keep on trying to activate the workflow if not an auth issue
|
||||||
this.addQueuedWorkflowActivation('init', workflowData);
|
this.addQueuedWorkflowActivation('init', workflowData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Logger.verbose('Finished initializing active workflows (startup)');
|
Logger.verbose('Finished initializing active workflows (startup)');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,7 +352,9 @@ export class ActiveWorkflowRunner {
|
||||||
select: ['id'],
|
select: ['id'],
|
||||||
where: { active: true },
|
where: { active: true },
|
||||||
});
|
});
|
||||||
return activeWorkflows.map((workflow) => workflow.id.toString());
|
return activeWorkflows
|
||||||
|
.map((workflow) => workflow.id)
|
||||||
|
.filter((workflowId) => !this.activationErrors[workflowId]);
|
||||||
} else {
|
} else {
|
||||||
const active = await Db.collections.Workflow.find({
|
const active = await Db.collections.Workflow.find({
|
||||||
select: ['id'],
|
select: ['id'],
|
||||||
|
@ -366,7 +370,9 @@ export class ActiveWorkflowRunner {
|
||||||
select: ['workflowId'],
|
select: ['workflowId'],
|
||||||
where,
|
where,
|
||||||
});
|
});
|
||||||
return shared.map((id) => id.workflowId.toString());
|
return shared
|
||||||
|
.map((id) => id.workflowId)
|
||||||
|
.filter((workflowId) => !this.activationErrors[workflowId]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
import { mocked } from 'jest-mock';
|
import { mocked } from 'jest-mock';
|
||||||
|
|
||||||
import type { ICredentialTypes, INodesAndCredentials } from 'n8n-workflow';
|
import type { ICredentialTypes, INode, INodesAndCredentials } from 'n8n-workflow';
|
||||||
import { LoggerProxy, NodeOperationError, Workflow } from 'n8n-workflow';
|
import { LoggerProxy, NodeApiError, NodeOperationError, Workflow } from 'n8n-workflow';
|
||||||
|
|
||||||
import { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
|
import { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
|
||||||
import * as Db from '@/Db';
|
import * as Db from '@/Db';
|
||||||
|
@ -51,7 +51,7 @@ const generateWorkflows = (count: number): WorkflowEntity[] => {
|
||||||
for (let i = 0; i < count; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
const workflow = new WorkflowEntity();
|
const workflow = new WorkflowEntity();
|
||||||
Object.assign(workflow, {
|
Object.assign(workflow, {
|
||||||
id: i + 1,
|
id: (i + 1).toString(),
|
||||||
name: randomName(),
|
name: randomName(),
|
||||||
active: true,
|
active: true,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
|
@ -260,4 +260,35 @@ describe('ActiveWorkflowRunner', () => {
|
||||||
activeWorkflowRunner.executeErrorWorkflow(error, workflowData, 'trigger');
|
activeWorkflowRunner.executeErrorWorkflow(error, workflowData, 'trigger');
|
||||||
expect(workflowExecuteAdditionalDataExecuteErrorWorkflowSpy).toHaveBeenCalledTimes(1);
|
expect(workflowExecuteAdditionalDataExecuteErrorWorkflowSpy).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('init()', () => {
|
||||||
|
it('should execute error workflow on failure to activate due to 401', async () => {
|
||||||
|
databaseActiveWorkflowsCount = 1;
|
||||||
|
|
||||||
|
jest.spyOn(ActiveWorkflowRunner.prototype, 'add').mockImplementation(() => {
|
||||||
|
throw new NodeApiError(
|
||||||
|
{
|
||||||
|
id: 'a75dcd1b-9fed-4643-90bd-75933d67936c',
|
||||||
|
name: 'Github Trigger',
|
||||||
|
type: 'n8n-nodes-base.githubTrigger',
|
||||||
|
typeVersion: 1,
|
||||||
|
position: [0, 0],
|
||||||
|
} as INode,
|
||||||
|
{
|
||||||
|
httpCode: '401',
|
||||||
|
message: 'Authorization failed - please check your credentials',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const executeSpy = jest.spyOn(ActiveWorkflowRunner.prototype, 'executeErrorWorkflow');
|
||||||
|
|
||||||
|
await activeWorkflowRunner.init();
|
||||||
|
|
||||||
|
const [error, workflow] = executeSpy.mock.calls[0];
|
||||||
|
|
||||||
|
expect(error.message).toContain('Authorization');
|
||||||
|
expect(workflow.id).toBe('1');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue