refactor(core): Make Logger a service (no-changelog) (#7494)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-10-25 16:35:22 +02:00
committed by GitHub
parent db4e61ba24
commit 05586a900d
131 changed files with 761 additions and 919 deletions

View File

@@ -27,7 +27,6 @@ import {
NodeHelpers,
Workflow,
WorkflowActivationError,
LoggerProxy as Logger,
ErrorReporterProxy as ErrorReporter,
WebhookPathAlreadyTakenError,
} from 'n8n-workflow';
@@ -66,6 +65,7 @@ import { WorkflowsService } from './workflows/workflows.services';
import { webhookNotFoundErrorMessage } from './utils';
import { In } from 'typeorm';
import { WebhookService } from './services/webhook.service';
import { Logger } from './Logger';
const WEBHOOK_PROD_UNREGISTERED_HINT =
"The workflow must be active for a production URL to run successfully. You can activate the workflow using the toggle in the top-right of the editor. Note that unlike test URL calls, production URL calls aren't shown on the canvas (only in the executions list)";
@@ -83,10 +83,11 @@ export class ActiveWorkflowRunner implements IWebhookManager {
} = {};
constructor(
private activeExecutions: ActiveExecutions,
private externalHooks: ExternalHooks,
private nodeTypes: NodeTypes,
private webhookService: WebhookService,
private readonly logger: Logger,
private readonly activeExecutions: ActiveExecutions,
private readonly externalHooks: ExternalHooks,
private readonly nodeTypes: NodeTypes,
private readonly webhookService: WebhookService,
) {}
async init() {
@@ -113,31 +114,31 @@ export class ActiveWorkflowRunner implements IWebhookManager {
}
if (workflowsData.length !== 0) {
Logger.info(' ================================');
Logger.info(' Start Active Workflows:');
Logger.info(' ================================');
this.logger.info(' ================================');
this.logger.info(' Start Active Workflows:');
this.logger.info(' ================================');
for (const workflowData of workflowsData) {
Logger.info(` - ${workflowData.name} (ID: ${workflowData.id})`);
Logger.debug(`Initializing active workflow "${workflowData.name}" (startup)`, {
this.logger.info(` - ${workflowData.name} (ID: ${workflowData.id})`);
this.logger.debug(`Initializing active workflow "${workflowData.name}" (startup)`, {
workflowName: workflowData.name,
workflowId: workflowData.id,
});
try {
await this.add(workflowData.id, 'init', workflowData);
Logger.verbose(`Successfully started workflow "${workflowData.name}"`, {
this.logger.verbose(`Successfully started workflow "${workflowData.name}"`, {
workflowName: workflowData.name,
workflowId: workflowData.id,
});
Logger.info(' => Started');
this.logger.info(' => Started');
} catch (error) {
ErrorReporter.error(error);
Logger.info(
this.logger.info(
' => ERROR: Workflow could not be activated on first try, keep on trying if not an auth issue',
);
Logger.info(` ${error.message}`);
Logger.error(
this.logger.info(` ${error.message}`);
this.logger.error(
`Issue on initial workflow activation try "${workflowData.name}" (startup)`,
{
workflowName: workflowData.name,
@@ -153,7 +154,7 @@ export class ActiveWorkflowRunner implements IWebhookManager {
}
}
}
Logger.verbose('Finished initializing active workflows (startup)');
this.logger.verbose('Finished initializing active workflows (startup)');
}
await this.externalHooks.run('activeWorkflows.initialized', []);
@@ -165,7 +166,7 @@ export class ActiveWorkflowRunner implements IWebhookManager {
*/
async removeAll(): Promise<void> {
let activeWorkflowIds: string[] = [];
Logger.verbose('Call to remove all active workflows received (removeAll)');
this.logger.verbose('Call to remove all active workflows received (removeAll)');
activeWorkflowIds.push(...this.activeWorkflows.allActiveWorkflows());
@@ -192,7 +193,7 @@ export class ActiveWorkflowRunner implements IWebhookManager {
const httpMethod = request.method;
let path = request.params.path;
Logger.debug(`Received webhook "${httpMethod}" for path "${path}"`);
this.logger.debug(`Received webhook "${httpMethod}" for path "${path}"`);
// Reset request parameters
request.params = {} as WebhookRequest['params'];
@@ -421,7 +422,7 @@ export class ActiveWorkflowRunner implements IWebhookManager {
await this.removeWorkflowWebhooks(workflow.id);
} catch (error1) {
ErrorReporter.error(error1);
Logger.error(
this.logger.error(
`Could not remove webhooks of workflow "${workflow.id}" because of error: "${error1.message}"`,
);
}
@@ -558,7 +559,7 @@ export class ActiveWorkflowRunner implements IWebhookManager {
responsePromise?: IDeferredPromise<IExecuteResponsePromiseData>,
donePromise?: IDeferredPromise<IRun | undefined>,
): void => {
Logger.debug(`Received event to trigger execution for workflow "${workflow.name}"`);
this.logger.debug(`Received event to trigger execution for workflow "${workflow.name}"`);
void WorkflowsService.saveStaticData(workflow);
const executePromise = this.runWorkflow(
workflowData,
@@ -577,7 +578,7 @@ export class ActiveWorkflowRunner implements IWebhookManager {
.catch(donePromise.reject);
});
} else {
void executePromise.catch(Logger.error);
void executePromise.catch((error: Error) => this.logger.error(error.message, { error }));
}
};
@@ -614,7 +615,7 @@ export class ActiveWorkflowRunner implements IWebhookManager {
responsePromise?: IDeferredPromise<IExecuteResponsePromiseData>,
donePromise?: IDeferredPromise<IRun | undefined>,
): void => {
Logger.debug(`Received trigger for workflow "${workflow.name}"`);
this.logger.debug(`Received trigger for workflow "${workflow.name}"`);
void WorkflowsService.saveStaticData(workflow);
const executePromise = this.runWorkflow(
@@ -634,11 +635,11 @@ export class ActiveWorkflowRunner implements IWebhookManager {
.catch(donePromise.reject);
});
} else {
executePromise.catch(Logger.error);
executePromise.catch((error: Error) => this.logger.error(error.message, { error }));
}
};
returnFunctions.emitError = (error: Error): void => {
Logger.info(
this.logger.info(
`The trigger node "${node.name}" of workflow "${workflowData.name}" failed with the error: "${error.message}". Will try to reactivate.`,
{
nodeName: node.name,
@@ -728,7 +729,7 @@ export class ActiveWorkflowRunner implements IWebhookManager {
const canBeActivated = workflowInstance.checkIfWorkflowCanBeActivated(STARTING_NODES);
if (!canBeActivated) {
Logger.error(`Unable to activate workflow "${workflowData.name}"`);
this.logger.error(`Unable to activate workflow "${workflowData.name}"`);
throw new Error(
'The workflow can not be activated because it does not contain any nodes which could start the workflow. Only workflows which have trigger or webhook nodes can be activated.',
);
@@ -771,7 +772,7 @@ export class ActiveWorkflowRunner implements IWebhookManager {
getTriggerFunctions,
getPollFunctions,
);
Logger.verbose(`Successfully activated workflow "${workflowData.name}"`, {
this.logger.verbose(`Successfully activated workflow "${workflowData.name}"`, {
workflowId,
workflowName: workflowData.name,
});
@@ -828,7 +829,7 @@ export class ActiveWorkflowRunner implements IWebhookManager {
const workflowName = workflowData.name;
const retryFunction = async () => {
Logger.info(`Try to activate workflow "${workflowName}" (${workflowId})`, {
this.logger.info(`Try to activate workflow "${workflowName}" (${workflowId})`, {
workflowId,
workflowName,
});
@@ -841,7 +842,7 @@ export class ActiveWorkflowRunner implements IWebhookManager {
lastTimeout = Math.min(lastTimeout * 2, WORKFLOW_REACTIVATE_MAX_TIMEOUT);
}
Logger.info(
this.logger.info(
` -> Activation of workflow "${workflowName}" (${workflowId}) did fail with error: "${
error.message as string
}" | retry in ${Math.floor(lastTimeout / 1000)} seconds`,
@@ -855,10 +856,13 @@ export class ActiveWorkflowRunner implements IWebhookManager {
this.queuedWorkflowActivations[workflowId].timeout = setTimeout(retryFunction, lastTimeout);
return;
}
Logger.info(` -> Activation of workflow "${workflowName}" (${workflowId}) was successful!`, {
workflowId,
workflowName,
});
this.logger.info(
` -> Activation of workflow "${workflowName}" (${workflowId}) was successful!`,
{
workflowId,
workflowName,
},
);
};
// Just to be sure that there is not chance that for any reason
@@ -904,7 +908,7 @@ export class ActiveWorkflowRunner implements IWebhookManager {
await this.removeWorkflowWebhooks(workflowId);
} catch (error) {
ErrorReporter.error(error);
Logger.error(
this.logger.error(
`Could not remove webhooks of workflow "${workflowId}" because of error: "${error.message}"`,
);
}
@@ -923,7 +927,7 @@ export class ActiveWorkflowRunner implements IWebhookManager {
if (this.activeWorkflows.isActive(workflowId)) {
const removalSuccess = await this.activeWorkflows.remove(workflowId);
if (removalSuccess) {
Logger.verbose(`Successfully deactivated workflow "${workflowId}"`, { workflowId });
this.logger.verbose(`Successfully deactivated workflow "${workflowId}"`, { workflowId });
}
}
}