refactor: Rename runner broker uri

Rename `N8N_RUNNERS_N8N_URI` to `N8N_RUNNERS_TASK_BROKER_URI` to match what launcher is using.
This commit is contained in:
Tomi Turtiainen 2024-12-03 10:20:33 +02:00
parent 7ad4badd2d
commit 1424ddb7a5
5 changed files with 15 additions and 15 deletions

View file

@ -8,7 +8,7 @@
"allowed-env": [ "allowed-env": [
"PATH", "PATH",
"N8N_RUNNERS_GRANT_TOKEN", "N8N_RUNNERS_GRANT_TOKEN",
"N8N_RUNNERS_N8N_URI", "N8N_RUNNERS_TASK_BROKER_URI",
"N8N_RUNNERS_MAX_PAYLOAD", "N8N_RUNNERS_MAX_PAYLOAD",
"N8N_RUNNERS_MAX_CONCURRENCY", "N8N_RUNNERS_MAX_CONCURRENCY",
"N8N_RUNNERS_SERVER_ENABLED", "N8N_RUNNERS_SERVER_ENABLED",

View file

@ -14,8 +14,8 @@ class HealthcheckServerConfig {
@Config @Config
export class BaseRunnerConfig { export class BaseRunnerConfig {
@Env('N8N_RUNNERS_N8N_URI') @Env('N8N_RUNNERS_TASK_BROKER_URI')
n8nUri: string = '127.0.0.1:5679'; taskBrokerUri: string = '127.0.0.1:5679';
@Env('N8N_RUNNERS_GRANT_TOKEN') @Env('N8N_RUNNERS_GRANT_TOKEN')
grantToken: string = ''; grantToken: string = '';

View file

@ -34,7 +34,7 @@ describe('JsTaskRunner', () => {
...defaultConfig.baseRunnerConfig, ...defaultConfig.baseRunnerConfig,
grantToken: 'grantToken', grantToken: 'grantToken',
maxConcurrency: 1, maxConcurrency: 1,
n8nUri: 'localhost', taskBrokerUri: 'localhost',
...baseRunnerOpts, ...baseRunnerOpts,
}, },
jsRunnerConfig: { jsRunnerConfig: {
@ -311,10 +311,10 @@ describe('JsTaskRunner', () => {
}); });
it("should not expose task runner's env variables even if no env state is received", async () => { it("should not expose task runner's env variables even if no env state is received", async () => {
process.env.N8N_RUNNERS_N8N_URI = 'http://127.0.0.1:5679'; process.env.N8N_RUNNERS_TASK_BROKER_URI = 'http://127.0.0.1:5679';
const outcome = await execTaskWithParams({ const outcome = await execTaskWithParams({
task: newTaskWithSettings({ task: newTaskWithSettings({
code: 'return { val: $env.N8N_RUNNERS_N8N_URI }', code: 'return { val: $env.N8N_RUNNERS_TASK_BROKER_URI }',
nodeMode: 'runOnceForAllItems', nodeMode: 'runOnceForAllItems',
}), }),
taskData: newDataRequestResponse(inputItems.map(wrapIntoJson), { taskData: newDataRequestResponse(inputItems.map(wrapIntoJson), {

View file

@ -92,7 +92,7 @@ export abstract class TaskRunner extends EventEmitter {
this.maxConcurrency = opts.maxConcurrency; this.maxConcurrency = opts.maxConcurrency;
this.idleTimeout = opts.idleTimeout; this.idleTimeout = opts.idleTimeout;
const wsUrl = `ws://${opts.n8nUri}/runners/_ws?id=${this.id}`; const wsUrl = `ws://${opts.taskBrokerUri}/runners/_ws?id=${this.id}`;
this.ws = new WebSocket(wsUrl, { this.ws = new WebSocket(wsUrl, {
headers: { headers: {
authorization: `Bearer ${opts.grantToken}`, authorization: `Bearer ${opts.grantToken}`,
@ -109,11 +109,11 @@ export abstract class TaskRunner extends EventEmitter {
['ECONNREFUSED', 'ENOTFOUND'].some((code) => code === error.code) ['ECONNREFUSED', 'ENOTFOUND'].some((code) => code === error.code)
) { ) {
console.error( console.error(
`Error: Failed to connect to n8n. Please ensure n8n is reachable at: ${opts.n8nUri}`, `Error: Failed to connect to n8n. Please ensure n8n is reachable at: ${opts.taskBrokerUri}`,
); );
process.exit(1); process.exit(1);
} else { } else {
console.error(`Error: Failed to connect to n8n at ${opts.n8nUri}`); console.error(`Error: Failed to connect to n8n at ${opts.taskBrokerUri}`);
console.error('Details:', event.message || 'Unknown error'); console.error('Details:', event.message || 'Unknown error');
} }
}); });

View file

@ -94,19 +94,19 @@ export class TaskRunnerProcess extends TypedEmitter<TaskRunnerProcessEventMap> {
const grantToken = await this.authService.createGrantToken(); const grantToken = await this.authService.createGrantToken();
const n8nUri = `127.0.0.1:${this.runnerConfig.port}`; const taskBrokerUri = `127.0.0.1:${this.runnerConfig.port}`;
this.process = this.startNode(grantToken, n8nUri); this.process = this.startNode(grantToken, taskBrokerUri);
forwardToLogger(this.logger, this.process, '[Task Runner]: '); forwardToLogger(this.logger, this.process, '[Task Runner]: ');
this.monitorProcess(this.process); this.monitorProcess(this.process);
} }
startNode(grantToken: string, n8nUri: string) { startNode(grantToken: string, taskBrokerUri: string) {
const startScript = require.resolve('@n8n/task-runner/start'); const startScript = require.resolve('@n8n/task-runner/start');
return spawn('node', [startScript], { return spawn('node', [startScript], {
env: this.getProcessEnvVars(grantToken, n8nUri), env: this.getProcessEnvVars(grantToken, taskBrokerUri),
}); });
} }
@ -158,10 +158,10 @@ export class TaskRunnerProcess extends TypedEmitter<TaskRunnerProcessEventMap> {
} }
} }
private getProcessEnvVars(grantToken: string, n8nUri: string) { private getProcessEnvVars(grantToken: string, taskBrokerUri: string) {
const envVars: Record<string, string> = { const envVars: Record<string, string> = {
N8N_RUNNERS_GRANT_TOKEN: grantToken, N8N_RUNNERS_GRANT_TOKEN: grantToken,
N8N_RUNNERS_N8N_URI: n8nUri, N8N_RUNNERS_TASK_BROKER_URI: taskBrokerUri,
N8N_RUNNERS_MAX_PAYLOAD: this.runnerConfig.maxPayload.toString(), N8N_RUNNERS_MAX_PAYLOAD: this.runnerConfig.maxPayload.toString(),
N8N_RUNNERS_MAX_CONCURRENCY: this.runnerConfig.maxConcurrency.toString(), N8N_RUNNERS_MAX_CONCURRENCY: this.runnerConfig.maxConcurrency.toString(),
...this.getPassthroughEnvVars(), ...this.getPassthroughEnvVars(),