feat(core): Add metadata (customdata) to event log (#6334)

* add metadata (customdata) to event log

* lint fix

* use reduce
This commit is contained in:
Michael Auerswald 2023-05-30 17:59:55 +02:00 committed by GitHub
parent f91d36cd30
commit 792b1c1ffb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View file

@ -31,6 +31,7 @@ import type { User } from '@db/entities/User';
import { N8N_VERSION } from '@/constants';
import * as Db from '@/Db';
import { NodeTypes } from './NodeTypes';
import type { ExecutionMetadata } from './databases/entities/ExecutionMetadata';
function userToPayload(user: User): {
userId: string;
@ -253,7 +254,17 @@ export class InternalHooks implements IInternalHooksClass {
executionId: string,
executionMode: WorkflowExecuteMode,
workflowData?: IWorkflowBase,
executionMetadata?: ExecutionMetadata[],
): Promise<void> {
let metaData;
try {
if (executionMetadata) {
metaData = executionMetadata.reduce((acc, meta) => {
return { ...acc, [meta.key]: meta.value };
}, {});
}
} catch {}
void Promise.all([
eventBus.sendWorkflowEvent({
eventName: 'n8n.workflow.crashed',
@ -262,6 +273,7 @@ export class InternalHooks implements IInternalHooksClass {
isManual: executionMode === 'manual',
workflowId: workflowData?.id?.toString(),
workflowName: workflowData?.name,
metaData,
},
}),
]);
@ -430,6 +442,7 @@ export class InternalHooks implements IInternalHooksClass {
workflowId: properties.workflow_id,
isManual: properties.is_manual,
workflowName: workflow.name,
metaData: runData?.data?.resultData?.metadata,
},
})
: eventBus.sendWorkflowEvent({
@ -445,6 +458,7 @@ export class InternalHooks implements IInternalHooksClass {
errorMessage: properties.error_message?.toString(),
isManual: properties.is_manual,
workflowName: workflow.name,
metaData: runData?.data?.resultData?.metadata,
},
}),
);

View file

@ -133,6 +133,7 @@ export class WorkflowRunner {
executionId,
executionMode,
executionFlattedData?.workflowData,
executionFlattedData?.metadata,
);
} catch {
// Ignore errors

View file

@ -359,7 +359,11 @@ export class MessageEventBusDestinationWebhook
}
}
} catch (error) {
console.error(error);
LoggerProxy.warn(
`Webhook destination ${this.label} failed to send message to: ${this.url} - ${
(error as Error).message
}`,
);
}
return sendResult;