refactor(core): Extract ActiveWebhooks out of ActiveWorkflowRunner (no-changelog) (#8171)

## Summary
This PR continues refactoring webhooks code for better modularity.
Continued from #8069 to bring back `ActiveWebhooks`, but this time
actually handling active webhook calls in this class.

## Review / Merge checklist
- [x] PR title and summary are descriptive
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-12-28 10:04:32 +01:00
committed by GitHub
parent 68cff4c59e
commit c84d3c3bbf
4 changed files with 170 additions and 159 deletions

View File

@@ -7,7 +7,6 @@ import isbot from 'isbot';
import config from '@/config';
import { N8N_VERSION, inDevelopment, inTest } from '@/constants';
import { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
import * as Db from '@/Db';
import { N8nInstanceType } from '@/Interfaces';
import { ExternalHooks } from '@/ExternalHooks';
@@ -21,6 +20,7 @@ import { generateHostInstanceId } from './databases/utils/generators';
import { Logger } from '@/Logger';
import { ServiceUnavailableError } from './errors/response-errors/service-unavailable.error';
import { OnShutdown } from '@/decorators/OnShutdown';
import { ActiveWebhooks } from '@/ActiveWebhooks';
@Service()
export abstract class AbstractServer {
@@ -32,8 +32,6 @@ export abstract class AbstractServer {
protected externalHooks: ExternalHooks;
protected activeWorkflowRunner: ActiveWorkflowRunner;
protected protocol: string;
protected sslKey: string;
@@ -162,7 +160,6 @@ export abstract class AbstractServer {
await new Promise<void>((resolve) => this.server.listen(PORT, ADDRESS, () => resolve()));
this.externalHooks = Container.get(ExternalHooks);
this.activeWorkflowRunner = Container.get(ActiveWorkflowRunner);
await this.setupHealthCheck();
@@ -179,16 +176,13 @@ export abstract class AbstractServer {
// Setup webhook handlers before bodyParser, to let the Webhook node handle binary data in requests
if (this.webhooksEnabled) {
const activeWorkflowRunner = Container.get(ActiveWorkflowRunner);
const activeWebhooks = Container.get(ActiveWebhooks);
// Register a handler for active forms
this.app.all(`/${this.endpointForm}/:path(*)`, webhookRequestHandler(activeWorkflowRunner));
this.app.all(`/${this.endpointForm}/:path(*)`, webhookRequestHandler(activeWebhooks));
// Register a handler for active webhooks
this.app.all(
`/${this.endpointWebhook}/:path(*)`,
webhookRequestHandler(activeWorkflowRunner),
);
this.app.all(`/${this.endpointWebhook}/:path(*)`, webhookRequestHandler(activeWebhooks));
// Register a handler for waiting forms
this.app.all(