mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-20 11:22:15 +00:00
refactor(core): Revamp logs for scaling mode (#11244)
This commit is contained in:
@@ -12,7 +12,14 @@ import { Logger } from '@/logging/logger.service';
|
||||
import { NodeTypes } from '@/node-types';
|
||||
import * as WorkflowExecuteAdditionalData from '@/workflow-execute-additional-data';
|
||||
|
||||
import type { Job, JobId, JobResult, RunningJob } from './scaling.types';
|
||||
import type {
|
||||
Job,
|
||||
JobFinishedMessage,
|
||||
JobId,
|
||||
JobResult,
|
||||
RespondToWebhookMessage,
|
||||
RunningJob,
|
||||
} from './scaling.types';
|
||||
|
||||
/**
|
||||
* Responsible for processing jobs from the queue, i.e. running enqueued executions.
|
||||
@@ -26,7 +33,9 @@ export class JobProcessor {
|
||||
private readonly executionRepository: ExecutionRepository,
|
||||
private readonly workflowRepository: WorkflowRepository,
|
||||
private readonly nodeTypes: NodeTypes,
|
||||
) {}
|
||||
) {
|
||||
this.logger = this.logger.withScope('scaling');
|
||||
}
|
||||
|
||||
async processJob(job: Job): Promise<JobResult> {
|
||||
const { executionId, loadStaticData } = job.data;
|
||||
@@ -37,15 +46,18 @@ export class JobProcessor {
|
||||
});
|
||||
|
||||
if (!execution) {
|
||||
this.logger.error('[JobProcessor] Failed to find execution data', { executionId });
|
||||
throw new ApplicationError('Failed to find execution data. Aborting execution.', {
|
||||
extra: { executionId },
|
||||
});
|
||||
throw new ApplicationError(
|
||||
`Worker failed to find data for execution ${executionId} (job ${job.id})`,
|
||||
{ level: 'warning' },
|
||||
);
|
||||
}
|
||||
|
||||
const workflowId = execution.workflowData.id;
|
||||
|
||||
this.logger.info(`[JobProcessor] Starting job ${job.id} (execution ${executionId})`);
|
||||
this.logger.info(`Worker started execution ${executionId} (job ${job.id})`, {
|
||||
executionId,
|
||||
jobId: job.id,
|
||||
});
|
||||
|
||||
const startedAt = await this.executionRepository.setRunning(executionId);
|
||||
|
||||
@@ -58,8 +70,10 @@ export class JobProcessor {
|
||||
});
|
||||
|
||||
if (workflowData === null) {
|
||||
this.logger.error('[JobProcessor] Failed to find workflow', { workflowId, executionId });
|
||||
throw new ApplicationError('Failed to find workflow', { extra: { workflowId } });
|
||||
throw new ApplicationError(
|
||||
`Worker failed to find workflow ${workflowId} to run execution ${executionId} (job ${job.id})`,
|
||||
{ level: 'warning' },
|
||||
);
|
||||
}
|
||||
|
||||
staticData = workflowData.staticData;
|
||||
@@ -102,11 +116,14 @@ export class JobProcessor {
|
||||
|
||||
additionalData.hooks.hookFunctions.sendResponse = [
|
||||
async (response: IExecuteResponsePromiseData): Promise<void> => {
|
||||
await job.progress({
|
||||
const msg: RespondToWebhookMessage = {
|
||||
kind: 'respond-to-webhook',
|
||||
executionId,
|
||||
response: this.encodeWebhookResponse(response),
|
||||
});
|
||||
workerId: config.getEnv('redis.queueModeId'),
|
||||
};
|
||||
|
||||
await job.progress(msg);
|
||||
},
|
||||
];
|
||||
|
||||
@@ -115,7 +132,7 @@ export class JobProcessor {
|
||||
additionalData.setExecutionStatus = (status: ExecutionStatus) => {
|
||||
// Can't set the status directly in the queued worker, but it will happen in InternalHook.onWorkflowPostExecute
|
||||
this.logger.debug(
|
||||
`[JobProcessor] Queued worker execution status for ${executionId} is "${status}"`,
|
||||
`Queued worker execution status for execution ${executionId} (job ${job.id}) is "${status}"`,
|
||||
);
|
||||
};
|
||||
|
||||
@@ -148,7 +165,18 @@ export class JobProcessor {
|
||||
|
||||
delete this.runningJobs[job.id];
|
||||
|
||||
this.logger.debug('[JobProcessor] Job finished running', { jobId: job.id, executionId });
|
||||
this.logger.info(`Worker finished execution ${executionId} (job ${job.id})`, {
|
||||
executionId,
|
||||
jobId: job.id,
|
||||
});
|
||||
|
||||
const msg: JobFinishedMessage = {
|
||||
kind: 'job-finished',
|
||||
executionId,
|
||||
workerId: config.getEnv('redis.queueModeId'),
|
||||
};
|
||||
|
||||
await job.progress(msg);
|
||||
|
||||
/**
|
||||
* @important Do NOT call `workflowExecuteAfter` hook here.
|
||||
|
||||
Reference in New Issue
Block a user