Add loading staticData to worker

This commit is contained in:
Jan Oberhauser 2021-01-01 10:39:05 +01:00
parent 6fb6b509e5
commit f0ea2f8399
3 changed files with 20 additions and 4 deletions

View file

@ -14,6 +14,10 @@ import {
WorkflowHooks, WorkflowHooks,
} from 'n8n-workflow'; } from 'n8n-workflow';
import {
FindOneOptions,
} from 'type-orm';
import { import {
ActiveExecutions, ActiveExecutions,
CredentialsOverwrites, CredentialsOverwrites,
@ -42,9 +46,7 @@ export class Worker extends Command {
static flags = { static flags = {
help: flags.help({ char: 'h' }), help: flags.help({ char: 'h' }),
concurrency: flags.integer({ concurrency: flags.integer({
// default: 10, default: 10,
// TODO: Change setting
default: 1,
description: 'How many jobs can run in parallel.', description: 'How many jobs can run in parallel.',
}), }),
}; };
@ -123,7 +125,19 @@ export class Worker extends Command {
console.log(`Start job: ${job.id} (Workflow ID: ${jobData.workflowData.id})`); console.log(`Start job: ${job.id} (Workflow ID: ${jobData.workflowData.id})`);
// TODO: Can in the future query most of that data from the DB to lighten redis load // TODO: Can in the future query most of that data from the DB to lighten redis load
const workflow = new Workflow({ id: jobData.workflowData.id as string, name: jobData.workflowData.name, nodes: jobData.workflowData!.nodes, connections: jobData.workflowData!.connections, active: jobData.workflowData!.active, nodeTypes, staticData: jobData.workflowData!.staticData, settings: jobData.workflowData!.settings }); let staticData = jobData.workflowData!.staticData;
if (jobData.loadStaticData === true) {
const findOptions = {
select: ['id', 'staticData'],
} as FindOneOptions;
const workflowData = await Db.collections!.Workflow!.findOne(jobData.workflowData.id, findOptions);
if (workflowData === undefined) {
throw new Error(`The workflow with the ID "${jobData.workflowData.id}" could not be found`);
}
staticData = workflowData.staticData;
}
const workflow = new Workflow({ id: jobData.workflowData.id as string, name: jobData.workflowData.name, nodes: jobData.workflowData!.nodes, connections: jobData.workflowData!.connections, active: jobData.workflowData!.active, nodeTypes, staticData, settings: jobData.workflowData!.settings });
const credentials = await WorkflowCredentials(jobData.workflowData.nodes); const credentials = await WorkflowCredentials(jobData.workflowData.nodes);

View file

@ -38,6 +38,7 @@ export interface IBullJobData {
executionId: string; executionId: string;
executionMode: WorkflowExecuteMode; executionMode: WorkflowExecuteMode;
executionData?: IRunExecutionData; executionData?: IRunExecutionData;
loadStaticData: boolean;
runData?: IRunData; runData?: IRunData;
retryOf?: number | string | ObjectID; retryOf?: number | string | ObjectID;
startNodes?: string[]; startNodes?: string[];

View file

@ -221,6 +221,7 @@ export class WorkflowRunner {
executionId, executionId,
executionMode: data.executionMode, executionMode: data.executionMode,
executionData: data.executionData, executionData: data.executionData,
loadStaticData: !!loadStaticData,
retryOf: data.retryOf, retryOf: data.retryOf,
runData: data.runData, runData: data.runData,
startNodes: data.startNodes, startNodes: data.startNodes,