refactor(core): Set up ExecutionMetadata service (no-changelog) (#7103)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Iván Ovejero
2023-09-05 09:13:30 +02:00
committed by GitHub
parent cffda65b33
commit b7320f5322
3 changed files with 42 additions and 35 deletions

View File

@@ -62,11 +62,11 @@ import { findSubworkflowStart, isWorkflowIdValid } from '@/utils';
import { PermissionChecker } from './UserManagement/PermissionChecker';
import { WorkflowsService } from './workflows/workflows.services';
import { InternalHooks } from '@/InternalHooks';
import type { ExecutionMetadata } from '@db/entities/ExecutionMetadata';
import { ExecutionRepository } from '@db/repositories';
import { EventsService } from '@/services/events.service';
import { SecretsHelper } from './SecretsHelpers';
import { OwnershipService } from './services/ownership.service';
import { ExecutionMetadataService } from './services/executionMetadata.service';
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
*
@@ -663,7 +647,10 @@ function hookFunctionsSave(parentProcessMode?: string): IWorkflowExecuteHooks {
try {
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) {
Logger.error(`Failed to save metadata for execution ID ${this.executionId}`, e);
@@ -800,7 +787,10 @@ function hookFunctionsSaveWorker(): IWorkflowExecuteHooks {
try {
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) {
Logger.error(`Failed to save metadata for execution ID ${this.executionId}`, e);