Skip to content

Commit

Permalink
feat(core): Add metadata (customdata) to event log (#6334)
Browse files Browse the repository at this point in the history
* add metadata (customdata) to event log

* lint fix

* use reduce
  • Loading branch information
flipswitchingmonkey committed May 30, 2023
1 parent f91d36c commit 792b1c1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
14 changes: 14 additions & 0 deletions packages/cli/src/InternalHooks.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand All @@ -262,6 +273,7 @@ export class InternalHooks implements IInternalHooksClass {
isManual: executionMode === 'manual',
workflowId: workflowData?.id?.toString(),
workflowName: workflowData?.name,
metaData,
},
}),
]);
Expand Down Expand Up @@ -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({
Expand All @@ -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,
},
}),
);
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/WorkflowRunner.ts
Expand Up @@ -133,6 +133,7 @@ export class WorkflowRunner {
executionId,
executionMode,
executionFlattedData?.workflowData,
executionFlattedData?.metadata,
);
} catch {
// Ignore errors
Expand Down
Expand Up @@ -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;
Expand Down

0 comments on commit 792b1c1

Please sign in to comment.