Skip to content

Commit

Permalink
refactor(core): Validate job data on worker (#12548)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivov authored Jan 10, 2025
1 parent 4ca7942 commit 92d3de2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/cli/src/scaling/scaling.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GlobalConfig } from '@n8n/config';
import { Container, Service } from '@n8n/di';
import { ErrorReporter, InstanceSettings, Logger } from 'n8n-core';
import { ErrorReporter, InstanceSettings, isObjectLiteral, Logger } from 'n8n-core';
import {
ApplicationError,
BINARY_ENCODING,
Expand Down Expand Up @@ -93,6 +93,12 @@ export class ScalingService {

void this.queue.process(JOB_TYPE_NAME, concurrency, async (job: Job) => {
try {
if (!this.hasValidJobData(job)) {
throw new ApplicationError('Worker received invalid job', {
extra: { jobData: jsonStringify(job, { replaceCircularRefs: true }) },
});
}

await this.jobProcessor.processJob(job);
} catch (error) {
await this.reportJobProcessingError(ensureError(error), job);
Expand Down Expand Up @@ -503,5 +509,9 @@ export class ScalingService {
: jsonStringify(error, { replaceCircularRefs: true });
}

private hasValidJobData(job: Job) {
return isObjectLiteral(job.data) && 'executionId' in job.data && 'loadStaticData' in job.data;
}

// #endregion
}

0 comments on commit 92d3de2

Please sign in to comment.