mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 12:57:29 -08:00
fix(core): Revert transactions until we remove the legacy sqlite driver (#10299)
Some checks are pending
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions
Some checks are pending
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions
This commit is contained in:
parent
74e154b130
commit
1eba7c3c76
1
.github/workflows/test-workflows.yml
vendored
1
.github/workflows/test-workflows.yml
vendored
|
@ -73,6 +73,7 @@ jobs:
|
||||||
env:
|
env:
|
||||||
N8N_ENCRYPTION_KEY: ${{secrets.ENCRYPTION_KEY}}
|
N8N_ENCRYPTION_KEY: ${{secrets.ENCRYPTION_KEY}}
|
||||||
SKIP_STATISTICS_EVENTS: true
|
SKIP_STATISTICS_EVENTS: true
|
||||||
|
DB_SQLITE_POOL_SIZE: 4
|
||||||
# -
|
# -
|
||||||
# name: Export credentials
|
# name: Export credentials
|
||||||
# if: always()
|
# if: always()
|
||||||
|
|
|
@ -274,23 +274,16 @@ export class ExecutionRepository extends Repository<ExecutionEntity> {
|
||||||
* Insert a new execution and its execution data using a transaction.
|
* Insert a new execution and its execution data using a transaction.
|
||||||
*/
|
*/
|
||||||
async createNewExecution(execution: ExecutionPayload): Promise<string> {
|
async createNewExecution(execution: ExecutionPayload): Promise<string> {
|
||||||
return await this.manager.transaction(async (transactionManager) => {
|
|
||||||
const { data, workflowData, ...rest } = execution;
|
const { data, workflowData, ...rest } = execution;
|
||||||
const insertResult = await transactionManager.insert(ExecutionEntity, rest);
|
const { identifiers: inserted } = await this.insert(rest);
|
||||||
const { id: executionId } = insertResult.identifiers[0] as { id: string };
|
const { id: executionId } = inserted[0] as { id: string };
|
||||||
|
|
||||||
const { connections, nodes, name, settings } = workflowData ?? {};
|
const { connections, nodes, name, settings } = workflowData ?? {};
|
||||||
await this.executionDataRepository.createExecutionDataForExecution(
|
await this.executionDataRepository.insert({
|
||||||
{
|
|
||||||
executionId,
|
executionId,
|
||||||
workflowData: { connections, nodes, name, settings, id: workflowData.id },
|
workflowData: { connections, nodes, name, settings, id: workflowData.id },
|
||||||
data: stringify(data),
|
data: stringify(data),
|
||||||
},
|
|
||||||
transactionManager,
|
|
||||||
);
|
|
||||||
|
|
||||||
return String(executionId);
|
|
||||||
});
|
});
|
||||||
|
return String(executionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async markAsCrashed(executionIds: string | string[]) {
|
async markAsCrashed(executionIds: string | string[]) {
|
||||||
|
|
|
@ -1,32 +1,13 @@
|
||||||
import { Service } from 'typedi';
|
import { Service } from 'typedi';
|
||||||
import type { EntityManager } from '@n8n/typeorm';
|
|
||||||
import type { IWorkflowBase } from 'n8n-workflow';
|
|
||||||
import { DataSource, In, Repository } from '@n8n/typeorm';
|
import { DataSource, In, Repository } from '@n8n/typeorm';
|
||||||
import { ExecutionData } from '../entities/ExecutionData';
|
import { ExecutionData } from '../entities/ExecutionData';
|
||||||
|
|
||||||
export interface CreateExecutionDataOpts extends Pick<ExecutionData, 'data' | 'executionId'> {
|
|
||||||
workflowData: Pick<IWorkflowBase, 'connections' | 'nodes' | 'name' | 'settings' | 'id'>;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class ExecutionDataRepository extends Repository<ExecutionData> {
|
export class ExecutionDataRepository extends Repository<ExecutionData> {
|
||||||
constructor(dataSource: DataSource) {
|
constructor(dataSource: DataSource) {
|
||||||
super(ExecutionData, dataSource.manager);
|
super(ExecutionData, dataSource.manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
async createExecutionDataForExecution(
|
|
||||||
executionData: CreateExecutionDataOpts,
|
|
||||||
transactionManager: EntityManager,
|
|
||||||
) {
|
|
||||||
const { data, executionId, workflowData } = executionData;
|
|
||||||
|
|
||||||
return await transactionManager.insert(ExecutionData, {
|
|
||||||
executionId,
|
|
||||||
data,
|
|
||||||
workflowData,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async findByExecutionIds(executionIds: string[]) {
|
async findByExecutionIds(executionIds: string[]) {
|
||||||
return await this.find({
|
return await this.find({
|
||||||
select: ['workflowData'],
|
select: ['workflowData'],
|
||||||
|
|
|
@ -52,34 +52,5 @@ describe('ExecutionRepository', () => {
|
||||||
});
|
});
|
||||||
expect(executionData?.data).toEqual('[{"resultData":"1"},{}]');
|
expect(executionData?.data).toEqual('[{"resultData":"1"},{}]');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not create execution if execution data insert fails', async () => {
|
|
||||||
const executionRepo = Container.get(ExecutionRepository);
|
|
||||||
const executionDataRepo = Container.get(ExecutionDataRepository);
|
|
||||||
|
|
||||||
const workflow = await createWorkflow({ settings: { executionOrder: 'v1' } });
|
|
||||||
jest
|
|
||||||
.spyOn(executionDataRepo, 'createExecutionDataForExecution')
|
|
||||||
.mockRejectedValueOnce(new Error());
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
async () =>
|
|
||||||
await executionRepo.createNewExecution({
|
|
||||||
workflowId: workflow.id,
|
|
||||||
data: {
|
|
||||||
//@ts-expect-error This is not needed for tests
|
|
||||||
resultData: {},
|
|
||||||
},
|
|
||||||
workflowData: workflow,
|
|
||||||
mode: 'manual',
|
|
||||||
startedAt: new Date(),
|
|
||||||
status: 'new',
|
|
||||||
finished: false,
|
|
||||||
}),
|
|
||||||
).rejects.toThrow();
|
|
||||||
|
|
||||||
const executionEntities = await executionRepo.find();
|
|
||||||
expect(executionEntities).toBeEmptyArray();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue