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 GitHub
parent 71e75e8a68
commit 1d14557461
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,12 @@
import { GlobalConfig } from '@n8n/config'; import { GlobalConfig } from '@n8n/config';
import { InstanceSettings } from 'n8n-core'; 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 type { IExecuteResponsePromiseData } from 'n8n-workflow';
import { strict } from 'node:assert'; import { strict } from 'node:assert';
import Container, { Service } from 'typedi'; import Container, { Service } from 'typedi';
@ -78,11 +84,22 @@ export class ScalingService {
this.assertWorker(); this.assertWorker();
this.assertQueue(); this.assertQueue();
void this.queue.process( void this.queue.process(JOB_TYPE_NAME, concurrency, async (job: Job) => {
JOB_TYPE_NAME, try {
concurrency, await this.jobProcessor.processJob(job);
async (job: Job) => 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'); this.logger.debug('[ScalingService] Worker setup completed');
} }