n8n/packages
Michael Auerswald 0c6169ee22
refactor(core): Move event and telemetry handling into workers in queue mode (#7138)
# Motivation

In Queue mode, finished executions would cause the main instance to
always pull all execution data from the database, unflatten it and then
use it to send out event log events and telemetry events, as well as
required returns to Respond to Webhook nodes etc.

This could cause OOM errors when the data was large, since it had to be
fully unpacked and transformed on the main instance’s side, using up a
lot of memory (and time).

This PR attempts to limit this behaviour to only happen in those
required cases where the data has to be forwarded to some waiting
webhook, for example.

# Changes

Execution data is only required in cases, where the active execution has
a `postExecutePromise` attached to it. These usually forward the data to
some other endpoint (e.g. a listening webhook connection).

By adding a helper `getPostExecutePromiseCount()`, we can decide that in
cases where there is nothing listening at all, there is no reason to
pull the data on the main instance.

Previously, there would always be postExecutePromises because the
telemetry events were called. Now, these have been moved into the
workers, which have been given the various InternalHooks calls to their
hook function arrays, so they themselves issue these telemetry and event
calls.

This results in all event log messages to now be logged on the worker’s
event log, as well as the worker’s eventbus being the one to send out
the events to destinations. The main event log does…pretty much nothing.

We are not logging executions on the main event log any more, because
this would require all events to be replicated 1:1 from the workers to
the main instance(s) (this IS possible and implemented, see the worker’s
`replicateToRedisEventLogFunction` - but it is not enabled to reduce the
amount of traffic over redis).

Partial events in the main log could confuse the recovery process and
would result in, ironically, the recovery corrupting the execution data
by considering them crashed.

# Refactor

I have also used the opportunity to reduce duplicate code and move some
of the hook functionality into
`packages/cli/src/executionLifecycleHooks/shared/sharedHookFunctions.ts`
in preparation for a future full refactor of the hooks
2023-09-14 07:58:15 +02:00
..
@n8n/client-oauth2 🚀 Release 1.4.0 (#7001) 2023-08-23 15:41:49 +02:00
@n8n_io/eslint-config ci: Improve the performance of the import/no-cycle linting rule (no-changelog) (#6985) 2023-08-22 13:44:50 +02:00
cli refactor(core): Move event and telemetry handling into workers in queue mode (#7138) 2023-09-14 07:58:15 +02:00
core 🚀 Release 1.7.0 (#7162) 2023-09-13 14:55:52 +02:00
design-system 🚀 Release 1.7.0 (#7162) 2023-09-13 14:55:52 +02:00
editor-ui fix(editor): Prevent duplicate creation of credential for OAuth2 (#7163) 2023-09-13 17:28:43 +02:00
node-dev 🚀 Release 1.7.0 (#7162) 2023-09-13 14:55:52 +02:00
nodes-base 🚀 Release 1.7.0 (#7162) 2023-09-13 14:55:52 +02:00
workflow 🚀 Release 1.7.0 (#7162) 2023-09-13 14:55:52 +02:00