Merge branch 'main' into next

This commit is contained in:
GitHub Actions Bot 2024-08-06 00:48:24 +00:00
commit 7276a404e4
3 changed files with 51 additions and 3 deletions

View File

@ -162,7 +162,7 @@ export default class Processor {
// for uncaught error, set to error
this.logger.error(
`execution (${this.execution.id}) run instruction [${node.type}] for node (${node.id}) failed: `,
{ error: err },
err,
);
job = {
result:

View File

@ -7,7 +7,7 @@
* 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 { 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', () => {
it('trigger should not be triggered more than once in same execution', async () => {
const workflow = await WorkflowModel.create({

View File

@ -113,7 +113,13 @@ async function handler(this: CollectionTrigger, workflow: WorkflowModel, data: M
},
);
} else {
if (transaction) {
transaction.afterCommit(() => {
this.workflow.trigger(workflow, { data: json, stack: context?.stack });
});
} else {
this.workflow.trigger(workflow, { data: json, stack: context?.stack });
}
}
}