Skip to content

Commit

Permalink
refactor(core): Don't use DB transactions on ExecutionRepository.crea…
Browse files Browse the repository at this point in the history
…teNewExecution (no-changelog)
  • Loading branch information
netroy committed Dec 12, 2023
1 parent 19e88ec commit c9bf57e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
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
37 changes: 26 additions & 11 deletions packages/cli/src/databases/repositories/execution.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type {
import config from '@/config';
import type { IGetExecutionsQueryFilter } from '@/executions/executions.service';
import { isAdvancedExecutionFiltersEnabled } from '@/executions/executionHelpers';
import type { ExecutionData } from '../entities/ExecutionData';
import { ExecutionData } from '../entities/ExecutionData';
import { ExecutionEntity } from '../entities/ExecutionEntity';
import { ExecutionMetadata } from '../entities/ExecutionMetadata';
import { ExecutionDataRepository } from './executionData.repository';
Expand Down Expand Up @@ -213,17 +213,32 @@ 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,
data: stringify(data),
});

return newExecution;
const { identifiers: inserted } = await this.manager
.createQueryBuilder()
.insert()
.into(ExecutionEntity)
.values([rest])
.returning('id')
.execute();

const { id: executionId } = inserted[0] as { id: string };
const { connections, nodes, name, pinData, staticData } = workflowData ?? {};
await this.manager
.createQueryBuilder()
.insert()
.into(ExecutionData)
.values([
{
executionId,
// @ts-ignore
workflowData: { connections, nodes, name, pinData: pinData!, staticData },
data: stringify(data),
},
])
.execute();
return executionId;
}

async markAsCrashed(executionIds: string[]) {
Expand Down
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

0 comments on commit c9bf57e

Please sign in to comment.