Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): Don't use DB transactions on ExecutionRepository.createNewExecution #8002

Merged
merged 3 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/cli/src/ActiveExecutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ export class ActiveExecutions {
fullExecutionData.workflowId = workflowId;
}

const executionResult =
await Container.get(ExecutionRepository).createNewExecution(fullExecutionData);
executionId = executionResult.id;
executionId = await Container.get(ExecutionRepository).createNewExecution(fullExecutionData);
if (executionId === undefined) {
throw new ApplicationError('There was an issue assigning an execution id to the execution');
}
Expand Down
16 changes: 8 additions & 8 deletions packages/cli/src/databases/repositories/execution.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,17 @@ export class ExecutionRepository extends Repository<ExecutionEntity> {
return rest;
}

async createNewExecution(execution: ExecutionPayload) {
async createNewExecution(execution: ExecutionPayload): Promise<string> {
const { data, workflowData, ...rest } = execution;

const newExecution = await this.save(rest);
await this.executionDataRepository.save({
execution: newExecution,
workflowData,
const { identifiers: inserted } = await this.insert(rest);
const { id: executionId } = inserted[0] as { id: string };
const { connections, nodes, name } = workflowData ?? {};
await this.executionDataRepository.insert({
executionId,
workflowData: { connections, nodes, name },
data: stringify(data),
});

return newExecution;
return String(executionId);
}

async markAsCrashed(executionIds: string[]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import Container from 'typedi';
import { ExecutionRepository } from '@db/repositories/execution.repository';
import { ExecutionDataRepository } from '@db/repositories/executionData.repository';
import * as testDb from '../../shared/testDb';
import { createWorkflow } from '../../shared/db/workflows';

describe('ExecutionRepository', () => {
beforeAll(async () => {
await testDb.init();
});

beforeEach(async () => {
await testDb.truncate(['Workflow', 'Execution']);
});

afterAll(async () => {
await testDb.terminate();
});

describe('createNewExecution', () => {
it('should save execution data', async () => {
const executionRepo = Container.get(ExecutionRepository);
const workflow = await createWorkflow();
const executionId = await executionRepo.createNewExecution({
workflowId: workflow.id,
data: {
resultData: {},
},
workflowData: workflow,
mode: 'manual',
startedAt: new Date(),
status: 'new',
finished: false,
});

expect(executionId).toBeDefined();

const executionEntity = await executionRepo.findOneBy({ id: executionId });
expect(executionEntity?.id).toEqual(executionId);
expect(executionEntity?.workflowId).toEqual(workflow.id);
expect(executionEntity?.status).toEqual('new');

const executionDataRepo = Container.get(ExecutionDataRepository);
const executionData = await executionDataRepo.findOneBy({ executionId });
expect(executionData?.workflowData).toEqual({
connections: workflow.connections,
nodes: workflow.nodes,
name: workflow.name,
});
expect(executionData?.data).toEqual('[{"resultData":"1"},{}]');
});
});
});
4 changes: 1 addition & 3 deletions packages/cli/test/unit/ActiveExecutions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ const FAKE_EXECUTION_ID = '15';
const FAKE_SECOND_EXECUTION_ID = '20';

const updateExistingExecution = jest.fn();
const createNewExecution = jest.fn(async () => {
return { id: FAKE_EXECUTION_ID };
});
const createNewExecution = jest.fn(async () => FAKE_EXECUTION_ID);

Container.set(ExecutionRepository, {
updateExistingExecution,
Expand Down
Loading