mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
refactor(core): Set up ExecutionMetadata service (no-changelog) (#7103)
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
@@ -62,11 +62,11 @@ import { findSubworkflowStart, isWorkflowIdValid } from '@/utils';
|
|||||||
import { PermissionChecker } from './UserManagement/PermissionChecker';
|
import { PermissionChecker } from './UserManagement/PermissionChecker';
|
||||||
import { WorkflowsService } from './workflows/workflows.services';
|
import { WorkflowsService } from './workflows/workflows.services';
|
||||||
import { InternalHooks } from '@/InternalHooks';
|
import { InternalHooks } from '@/InternalHooks';
|
||||||
import type { ExecutionMetadata } from '@db/entities/ExecutionMetadata';
|
|
||||||
import { ExecutionRepository } from '@db/repositories';
|
import { ExecutionRepository } from '@db/repositories';
|
||||||
import { EventsService } from '@/services/events.service';
|
import { EventsService } from '@/services/events.service';
|
||||||
import { SecretsHelper } from './SecretsHelpers';
|
import { SecretsHelper } from './SecretsHelpers';
|
||||||
import { OwnershipService } from './services/ownership.service';
|
import { OwnershipService } from './services/ownership.service';
|
||||||
|
import { ExecutionMetadataService } from './services/executionMetadata.service';
|
||||||
|
|
||||||
const ERROR_TRIGGER_TYPE = config.getEnv('nodes.errorTriggerType');
|
const ERROR_TRIGGER_TYPE = config.getEnv('nodes.errorTriggerType');
|
||||||
|
|
||||||
@@ -252,22 +252,6 @@ async function pruneExecutionData(this: WorkflowHooks): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function saveExecutionMetadata(
|
|
||||||
executionId: string,
|
|
||||||
executionMetadata: Record<string, string>,
|
|
||||||
): Promise<ExecutionMetadata[]> {
|
|
||||||
const metadataRows = [];
|
|
||||||
for (const [key, value] of Object.entries(executionMetadata)) {
|
|
||||||
metadataRows.push({
|
|
||||||
execution: { id: executionId },
|
|
||||||
key,
|
|
||||||
value,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return Db.collections.ExecutionMetadata.save(metadataRows);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns hook functions to push data to Editor-UI
|
* Returns hook functions to push data to Editor-UI
|
||||||
*
|
*
|
||||||
@@ -663,7 +647,10 @@ function hookFunctionsSave(parentProcessMode?: string): IWorkflowExecuteHooks {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (fullRunData.data.resultData.metadata) {
|
if (fullRunData.data.resultData.metadata) {
|
||||||
await saveExecutionMetadata(this.executionId, fullRunData.data.resultData.metadata);
|
await Container.get(ExecutionMetadataService).save(
|
||||||
|
this.executionId,
|
||||||
|
fullRunData.data.resultData.metadata,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Logger.error(`Failed to save metadata for execution ID ${this.executionId}`, e);
|
Logger.error(`Failed to save metadata for execution ID ${this.executionId}`, e);
|
||||||
@@ -800,7 +787,10 @@ function hookFunctionsSaveWorker(): IWorkflowExecuteHooks {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (fullRunData.data.resultData.metadata) {
|
if (fullRunData.data.resultData.metadata) {
|
||||||
await saveExecutionMetadata(this.executionId, fullRunData.data.resultData.metadata);
|
await Container.get(ExecutionMetadataService).save(
|
||||||
|
this.executionId,
|
||||||
|
fullRunData.data.resultData.metadata,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Logger.error(`Failed to save metadata for execution ID ${this.executionId}`, e);
|
Logger.error(`Failed to save metadata for execution ID ${this.executionId}`, e);
|
||||||
|
|||||||
24
packages/cli/src/services/executionMetadata.service.ts
Normal file
24
packages/cli/src/services/executionMetadata.service.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { ExecutionMetadataRepository } from '@/databases/repositories';
|
||||||
|
import { Service } from 'typedi';
|
||||||
|
import type { ExecutionMetadata } from '@/databases/entities/ExecutionMetadata';
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export class ExecutionMetadataService {
|
||||||
|
constructor(private readonly executionMetadataRepository: ExecutionMetadataRepository) {}
|
||||||
|
|
||||||
|
async save(
|
||||||
|
executionId: string,
|
||||||
|
executionMetadata: Record<string, string>,
|
||||||
|
): Promise<ExecutionMetadata[]> {
|
||||||
|
const metadataRows = [];
|
||||||
|
for (const [key, value] of Object.entries(executionMetadata)) {
|
||||||
|
metadataRows.push({
|
||||||
|
execution: { id: executionId },
|
||||||
|
key,
|
||||||
|
value,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.executionMetadataRepository.save(metadataRows);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +1,11 @@
|
|||||||
import { saveExecutionMetadata } from '@/WorkflowExecuteAdditionalData';
|
import { Container } from 'typedi';
|
||||||
import * as Db from '@/Db';
|
import { ExecutionMetadataRepository } from '@db/repositories';
|
||||||
import { mocked } from 'jest-mock';
|
import { ExecutionMetadataService } from '@/services/executionMetadata.service';
|
||||||
|
import { mockInstance } from '../integration/shared/utils';
|
||||||
jest.mock('@/Db', () => {
|
|
||||||
return {
|
|
||||||
collections: {
|
|
||||||
ExecutionMetadata: {
|
|
||||||
save: jest.fn(async () => []),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('WorkflowExecuteAdditionalData', () => {
|
describe('WorkflowExecuteAdditionalData', () => {
|
||||||
|
const repository = mockInstance(ExecutionMetadataRepository);
|
||||||
|
|
||||||
test('Execution metadata is saved in a batch', async () => {
|
test('Execution metadata is saved in a batch', async () => {
|
||||||
const toSave = {
|
const toSave = {
|
||||||
test1: 'value1',
|
test1: 'value1',
|
||||||
@@ -20,10 +13,10 @@ describe('WorkflowExecuteAdditionalData', () => {
|
|||||||
};
|
};
|
||||||
const executionId = '1234';
|
const executionId = '1234';
|
||||||
|
|
||||||
await saveExecutionMetadata(executionId, toSave);
|
await Container.get(ExecutionMetadataService).save(executionId, toSave);
|
||||||
|
|
||||||
expect(mocked(Db.collections.ExecutionMetadata.save)).toHaveBeenCalledTimes(1);
|
expect(repository.save).toHaveBeenCalledTimes(1);
|
||||||
expect(mocked(Db.collections.ExecutionMetadata.save).mock.calls[0]).toEqual([
|
expect(repository.save.mock.calls[0]).toEqual([
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
execution: { id: executionId },
|
execution: { id: executionId },
|
||||||
|
|||||||
Reference in New Issue
Block a user