mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 10:26:45 +00:00
fix(plugin-workflow): fix collection trigger in async mode after transaction committed (#4994)
This commit is contained in:
parent
d51559f9e2
commit
c4acdebcaa
@ -161,7 +161,7 @@ export default class Processor {
|
|||||||
// for uncaught error, set to error
|
// for uncaught error, set to error
|
||||||
this.logger.error(
|
this.logger.error(
|
||||||
`execution (${this.execution.id}) run instruction [${node.type}] for node (${node.id}) failed: `,
|
`execution (${this.execution.id}) run instruction [${node.type}] for node (${node.id}) failed: `,
|
||||||
{ error: err },
|
err,
|
||||||
);
|
);
|
||||||
job = {
|
job = {
|
||||||
result:
|
result:
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { BelongsToRepository, MockDatabase } from '@nocobase/database';
|
import { BelongsToRepository, MockDatabase, Op } from '@nocobase/database';
|
||||||
import { getApp, sleep } from '@nocobase/plugin-workflow-test';
|
import { getApp, sleep } from '@nocobase/plugin-workflow-test';
|
||||||
import { MockServer } from '@nocobase/test';
|
import { MockServer } from '@nocobase/test';
|
||||||
|
|
||||||
@ -652,6 +652,48 @@ describe('workflow > triggers > collection', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('transaction', () => {
|
||||||
|
it('should trigger after transaction committed', async () => {
|
||||||
|
const workflow = await WorkflowModel.create({
|
||||||
|
enabled: true,
|
||||||
|
type: 'collection',
|
||||||
|
config: {
|
||||||
|
mode: 1,
|
||||||
|
collection: 'posts',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await workflow.createNode({
|
||||||
|
type: 'destroy',
|
||||||
|
config: {
|
||||||
|
collection: 'posts',
|
||||||
|
params: {
|
||||||
|
filter: {
|
||||||
|
id: {
|
||||||
|
$not: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await db.sequelize.transaction(async (transaction) => {
|
||||||
|
const p1 = await PostRepo.create({ values: { title: 't1' }, transaction });
|
||||||
|
await sleep(50);
|
||||||
|
const p2 = await PostRepo.create({ values: { title: 't2' }, transaction });
|
||||||
|
await sleep(50);
|
||||||
|
});
|
||||||
|
|
||||||
|
await sleep(500);
|
||||||
|
|
||||||
|
const executions = await workflow.getExecutions();
|
||||||
|
expect(executions.length).toBe(2);
|
||||||
|
|
||||||
|
const posts = await PostRepo.find();
|
||||||
|
expect(posts.length).toBe(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('cycling trigger', () => {
|
describe('cycling trigger', () => {
|
||||||
it('trigger should not be triggered more than once in same execution', async () => {
|
it('trigger should not be triggered more than once in same execution', async () => {
|
||||||
const workflow = await WorkflowModel.create({
|
const workflow = await WorkflowModel.create({
|
||||||
|
@ -113,7 +113,13 @@ async function handler(this: CollectionTrigger, workflow: WorkflowModel, data: M
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
if (transaction) {
|
||||||
|
transaction.afterCommit(() => {
|
||||||
this.workflow.trigger(workflow, { data: json, stack: context?.stack });
|
this.workflow.trigger(workflow, { data: json, stack: context?.stack });
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.workflow.trigger(workflow, { data: json, stack: context?.stack });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user