feat(core): Support community packages in scaling-mode (#10228)
This commit is contained in:
committed by
GitHub
parent
afa43e75f6
commit
88086a41ff
@@ -44,13 +44,16 @@ export abstract class BaseCommand extends Command {
|
||||
|
||||
protected license: License;
|
||||
|
||||
protected globalConfig = Container.get(GlobalConfig);
|
||||
protected readonly globalConfig = Container.get(GlobalConfig);
|
||||
|
||||
/**
|
||||
* How long to wait for graceful shutdown before force killing the process.
|
||||
*/
|
||||
protected gracefulShutdownTimeoutInS = config.getEnv('generic.gracefulShutdownTimeout');
|
||||
|
||||
/** Whether to init community packages (if enabled) */
|
||||
protected needsCommunityPackages = false;
|
||||
|
||||
async init(): Promise<void> {
|
||||
await initErrorHandling();
|
||||
initExpressionEvaluator();
|
||||
@@ -111,6 +114,12 @@ export abstract class BaseCommand extends Command {
|
||||
);
|
||||
}
|
||||
|
||||
const { communityPackages } = this.globalConfig.nodes;
|
||||
if (communityPackages.enabled && this.needsCommunityPackages) {
|
||||
const { CommunityPackagesService } = await import('@/services/communityPackages.service');
|
||||
await Container.get(CommunityPackagesService).checkForMissingPackages();
|
||||
}
|
||||
|
||||
await Container.get(PostHogClient).init();
|
||||
await Container.get(InternalHooks).init();
|
||||
await Container.get(TelemetryEventRelay).init();
|
||||
|
||||
@@ -27,6 +27,8 @@ export class Execute extends BaseCommand {
|
||||
}),
|
||||
};
|
||||
|
||||
override needsCommunityPackages = true;
|
||||
|
||||
async init() {
|
||||
await super.init();
|
||||
await this.initBinaryDataService();
|
||||
|
||||
@@ -108,6 +108,8 @@ export class ExecuteBatch extends BaseCommand {
|
||||
}),
|
||||
};
|
||||
|
||||
override needsCommunityPackages = true;
|
||||
|
||||
/**
|
||||
* Gracefully handles exit.
|
||||
* @param {boolean} skipExit Whether to skip exit or number according to received signal
|
||||
|
||||
@@ -8,7 +8,6 @@ import { createReadStream, createWriteStream, existsSync } from 'fs';
|
||||
import { pipeline } from 'stream/promises';
|
||||
import replaceStream from 'replacestream';
|
||||
import glob from 'fast-glob';
|
||||
import { GlobalConfig } from '@n8n/config';
|
||||
import { jsonParse, randomString } from 'n8n-workflow';
|
||||
|
||||
import config from '@/config';
|
||||
@@ -68,6 +67,8 @@ export class Start extends BaseCommand {
|
||||
|
||||
protected server = Container.get(Server);
|
||||
|
||||
override needsCommunityPackages = true;
|
||||
|
||||
constructor(argv: string[], cmdConfig: Config) {
|
||||
super(argv, cmdConfig);
|
||||
this.setInstanceType('main');
|
||||
@@ -125,7 +126,6 @@ export class Start extends BaseCommand {
|
||||
private async generateStaticAssets() {
|
||||
// Read the index file and replace the path placeholder
|
||||
const n8nPath = this.globalConfig.path;
|
||||
|
||||
const hooksUrls = config.getEnv('externalFrontendHooksUrls');
|
||||
|
||||
let scriptsString = '';
|
||||
@@ -178,6 +178,22 @@ export class Start extends BaseCommand {
|
||||
this.logger.debug(`Queue mode id: ${this.queueModeId}`);
|
||||
}
|
||||
|
||||
const { flags } = await this.parse(Start);
|
||||
const { communityPackages } = this.globalConfig.nodes;
|
||||
// cli flag overrides the config env variable
|
||||
if (flags.reinstallMissingPackages) {
|
||||
if (communityPackages.enabled) {
|
||||
this.logger.warn(
|
||||
'`--reinstallMissingPackages` is deprecated: Please use the env variable `N8N_REINSTALL_MISSING_PACKAGES` instead',
|
||||
);
|
||||
communityPackages.reinstallMissing = true;
|
||||
} else {
|
||||
this.logger.warn(
|
||||
'`--reinstallMissingPackages` was passed, but community packages are disabled',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
await super.init();
|
||||
this.activeWorkflowManager = Container.get(ActiveWorkflowManager);
|
||||
|
||||
@@ -251,18 +267,9 @@ export class Start extends BaseCommand {
|
||||
config.set(setting.key, jsonParse(setting.value, { fallbackValue: setting.value }));
|
||||
});
|
||||
|
||||
const globalConfig = Container.get(GlobalConfig);
|
||||
|
||||
if (globalConfig.nodes.communityPackages.enabled) {
|
||||
const { CommunityPackagesService } = await import('@/services/communityPackages.service');
|
||||
await Container.get(CommunityPackagesService).setMissingPackages({
|
||||
reinstallMissingPackages: flags.reinstallMissingPackages,
|
||||
});
|
||||
}
|
||||
|
||||
const { type: dbType } = globalConfig.database;
|
||||
const { type: dbType } = this.globalConfig.database;
|
||||
if (dbType === 'sqlite') {
|
||||
const shouldRunVacuum = globalConfig.database.sqlite.executeVacuumOnStartup;
|
||||
const shouldRunVacuum = this.globalConfig.database.sqlite.executeVacuumOnStartup;
|
||||
if (shouldRunVacuum) {
|
||||
await Container.get(ExecutionRepository).query('VACUUM;');
|
||||
}
|
||||
@@ -282,7 +289,7 @@ export class Start extends BaseCommand {
|
||||
}
|
||||
|
||||
const { default: localtunnel } = await import('@n8n/localtunnel');
|
||||
const { port } = Container.get(GlobalConfig);
|
||||
const { port } = this.globalConfig;
|
||||
|
||||
const webhookTunnel = await localtunnel(port, {
|
||||
host: 'https://hooks.n8n.cloud',
|
||||
|
||||
@@ -22,6 +22,8 @@ export class Webhook extends BaseCommand {
|
||||
|
||||
protected server = Container.get(WebhookServer);
|
||||
|
||||
override needsCommunityPackages = true;
|
||||
|
||||
constructor(argv: string[], cmdConfig: Config) {
|
||||
super(argv, cmdConfig);
|
||||
this.setInstanceType('webhook');
|
||||
|
||||
@@ -3,7 +3,6 @@ import { Flags, type Config } from '@oclif/core';
|
||||
import express from 'express';
|
||||
import http from 'http';
|
||||
import type PCancelable from 'p-cancelable';
|
||||
import { GlobalConfig } from '@n8n/config';
|
||||
import { WorkflowExecute } from 'n8n-core';
|
||||
import type { ExecutionStatus, IExecuteResponsePromiseData, INodeTypes, IRun } from 'n8n-workflow';
|
||||
import { Workflow, sleep, ApplicationError } from 'n8n-workflow';
|
||||
@@ -57,6 +56,8 @@ export class Worker extends BaseCommand {
|
||||
|
||||
redisSubscriber: RedisServicePubSubSubscriber;
|
||||
|
||||
override needsCommunityPackages = true;
|
||||
|
||||
/**
|
||||
* Stop n8n in a graceful way.
|
||||
* Make for example sure that all the webhooks from third party services
|
||||
@@ -429,8 +430,7 @@ export class Worker extends BaseCommand {
|
||||
|
||||
let presetCredentialsLoaded = false;
|
||||
|
||||
const globalConfig = Container.get(GlobalConfig);
|
||||
const endpointPresetCredentials = globalConfig.credentials.overwrite.endpoint;
|
||||
const endpointPresetCredentials = this.globalConfig.credentials.overwrite.endpoint;
|
||||
if (endpointPresetCredentials !== '') {
|
||||
// POST endpoint to set preset credentials
|
||||
app.post(
|
||||
|
||||
Reference in New Issue
Block a user