mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 18:41:14 +00:00
feat: Make runner concurrency configurable (no-changelog) (#11448)
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { ApplicationError, type INodeTypeDescription } from 'n8n-workflow';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { URL } from 'node:url';
|
||||
import { type MessageEvent, WebSocket } from 'ws';
|
||||
|
||||
import type { BaseRunnerConfig } from './config/base-runner-config';
|
||||
import { TaskRunnerNodeTypes } from './node-types';
|
||||
import {
|
||||
RPC_ALLOW_LIST,
|
||||
@@ -42,7 +42,10 @@ export interface RPCCallObject {
|
||||
const VALID_TIME_MS = 1000;
|
||||
const VALID_EXTRA_MS = 100;
|
||||
|
||||
const DEFAULT_MAX_PAYLOAD_SIZE = 1024 * 1024 * 1024;
|
||||
export interface TaskRunnerOpts extends BaseRunnerConfig {
|
||||
taskType: string;
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export abstract class TaskRunner {
|
||||
id: string = nanoid();
|
||||
@@ -63,22 +66,23 @@ export abstract class TaskRunner {
|
||||
|
||||
nodeTypes: TaskRunnerNodeTypes = new TaskRunnerNodeTypes([]);
|
||||
|
||||
constructor(
|
||||
public taskType: string,
|
||||
wsUrl: string,
|
||||
grantToken: string,
|
||||
private maxConcurrency: number,
|
||||
public name?: string,
|
||||
) {
|
||||
const url = new URL(wsUrl);
|
||||
url.searchParams.append('id', this.id);
|
||||
this.ws = new WebSocket(url.toString(), {
|
||||
taskType: string;
|
||||
|
||||
maxConcurrency: number;
|
||||
|
||||
name: string;
|
||||
|
||||
constructor(opts: TaskRunnerOpts) {
|
||||
this.taskType = opts.taskType;
|
||||
this.name = opts.name ?? 'Node.js Task Runner SDK';
|
||||
this.maxConcurrency = opts.maxConcurrency;
|
||||
|
||||
const wsUrl = `ws://${opts.n8nUri}/runners/_ws?id=${this.id}`;
|
||||
this.ws = new WebSocket(wsUrl, {
|
||||
headers: {
|
||||
authorization: `Bearer ${grantToken}`,
|
||||
authorization: `Bearer ${opts.grantToken}`,
|
||||
},
|
||||
maxPayload: process.env.N8N_RUNNERS_MAX_PAYLOAD
|
||||
? parseInt(process.env.N8N_RUNNERS_MAX_PAYLOAD)
|
||||
: DEFAULT_MAX_PAYLOAD_SIZE,
|
||||
maxPayload: opts.maxPayloadSize,
|
||||
});
|
||||
this.ws.addEventListener('message', this.receiveMessage);
|
||||
this.ws.addEventListener('close', this.stopTaskOffers);
|
||||
@@ -145,7 +149,7 @@ export abstract class TaskRunner {
|
||||
case 'broker:inforequest':
|
||||
this.send({
|
||||
type: 'runner:info',
|
||||
name: this.name ?? 'Node.js Task Runner SDK',
|
||||
name: this.name,
|
||||
types: [this.taskType],
|
||||
});
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user