fix(core): Print errors that happen before the execution starts on the worker instead of just on the main instance (#11099)

This commit is contained in:
Danny Martini 2024-10-04 15:36:04 +02:00 committed by कारतोफ्फेलस्क्रिप्ट™
parent f91fae565c
commit 563a0fc446
No known key found for this signature in database

View file

@ -1,6 +1,12 @@
import { GlobalConfig } from '@n8n/config';
import { InstanceSettings } from 'n8n-core';
import { ApplicationError, BINARY_ENCODING, sleep, jsonStringify } from 'n8n-workflow';
import {
ApplicationError,
BINARY_ENCODING,
sleep,
jsonStringify,
ErrorReporterProxy,
} from 'n8n-workflow';
import type { IExecuteResponsePromiseData } from 'n8n-workflow';
import { strict } from 'node:assert';
import Container, { Service } from 'typedi';
@ -78,11 +84,22 @@ export class ScalingService {
this.assertWorker();
this.assertQueue();
void this.queue.process(
JOB_TYPE_NAME,
concurrency,
async (job: Job) => await this.jobProcessor.processJob(job),
);
void this.queue.process(JOB_TYPE_NAME, concurrency, async (job: Job) => {
try {
await this.jobProcessor.processJob(job);
} catch (error: unknown) {
// Errors thrown here will be sent to the main instance by bull. Logging
// them out and rethrowing them allows to find out which worker had the
// issue.
this.logger.error('[ScalingService] Executing a job errored', {
jobId: job.id,
executionId: job.data.executionId,
error,
});
ErrorReporterProxy.error(error);
throw error;
}
});
this.logger.debug('[ScalingService] Worker setup completed');
}