fix(plugin-workflow): fix duplicated downstream executions after condition (#2517)
This commit is contained in:
parent
8b054e6aac
commit
9154e531c2
@ -35,7 +35,6 @@ describe('workflow > instructions > condition', () => {
|
|||||||
describe('single calculation', () => {
|
describe('single calculation', () => {
|
||||||
it('calculation to true downstream', async () => {
|
it('calculation to true downstream', async () => {
|
||||||
const n1 = await workflow.createNode({
|
const n1 = await workflow.createNode({
|
||||||
title: 'condition',
|
|
||||||
type: 'condition',
|
type: 'condition',
|
||||||
config: {
|
config: {
|
||||||
engine: 'math.js',
|
engine: 'math.js',
|
||||||
@ -44,19 +43,24 @@ describe('workflow > instructions > condition', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const n2 = await workflow.createNode({
|
const n2 = await workflow.createNode({
|
||||||
title: 'true to echo',
|
|
||||||
type: 'echo',
|
type: 'echo',
|
||||||
branchIndex: BRANCH_INDEX.ON_TRUE,
|
branchIndex: BRANCH_INDEX.ON_TRUE,
|
||||||
upstreamId: n1.id,
|
upstreamId: n1.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
const n3 = await workflow.createNode({
|
const n3 = await workflow.createNode({
|
||||||
title: 'false to echo',
|
|
||||||
type: 'echo',
|
type: 'echo',
|
||||||
branchIndex: BRANCH_INDEX.ON_FALSE,
|
branchIndex: BRANCH_INDEX.ON_FALSE,
|
||||||
upstreamId: n1.id,
|
upstreamId: n1.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const n4 = await workflow.createNode({
|
||||||
|
type: 'echo',
|
||||||
|
upstreamId: n1.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
await n1.setDownstream(n4);
|
||||||
|
|
||||||
const post = await PostRepo.create({ values: { title: 't1' } });
|
const post = await PostRepo.create({ values: { title: 't1' } });
|
||||||
|
|
||||||
await sleep(500);
|
await sleep(500);
|
||||||
@ -64,9 +68,12 @@ describe('workflow > instructions > condition', () => {
|
|||||||
const [execution] = await workflow.getExecutions();
|
const [execution] = await workflow.getExecutions();
|
||||||
expect(execution.status).toEqual(EXECUTION_STATUS.RESOLVED);
|
expect(execution.status).toEqual(EXECUTION_STATUS.RESOLVED);
|
||||||
|
|
||||||
const jobs = await execution.getJobs();
|
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
||||||
expect(jobs.length).toEqual(2);
|
expect(jobs.length).toEqual(3);
|
||||||
expect(jobs[1].result).toEqual(true);
|
expect(jobs[1].result).toEqual(true);
|
||||||
|
expect(jobs[1].nodeId).toEqual(n2.id);
|
||||||
|
expect(jobs[2].result).toEqual(true);
|
||||||
|
expect(jobs[2].nodeId).toEqual(n4.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calculation to false downstream', async () => {
|
it('calculation to false downstream', async () => {
|
||||||
|
@ -3,7 +3,7 @@ import { Registry } from '@nocobase/utils';
|
|||||||
import { Instruction } from '.';
|
import { Instruction } from '.';
|
||||||
import { Processor } from '..';
|
import { Processor } from '..';
|
||||||
import { JOB_STATUS } from '../constants';
|
import { JOB_STATUS } from '../constants';
|
||||||
import type { FlowNodeModel } from '../types';
|
import type { FlowNodeModel, JobModel } from '../types';
|
||||||
|
|
||||||
type Comparer = (a: any, b: any) => boolean;
|
type Comparer = (a: any, b: any) => boolean;
|
||||||
|
|
||||||
@ -157,16 +157,20 @@ export default {
|
|||||||
|
|
||||||
const savedJob = await processor.saveJob(job);
|
const savedJob = await processor.saveJob(job);
|
||||||
|
|
||||||
return processor.run(branchNode, savedJob);
|
await processor.run(branchNode, savedJob);
|
||||||
|
|
||||||
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
async resume(node: FlowNodeModel, branchJob, processor: Processor) {
|
async resume(node: FlowNodeModel, branchJob: JobModel, processor: Processor) {
|
||||||
|
const job = processor.findBranchParentJob(branchJob, node) as JobModel;
|
||||||
|
|
||||||
if (branchJob.status === JOB_STATUS.RESOLVED) {
|
if (branchJob.status === JOB_STATUS.RESOLVED) {
|
||||||
// return to continue node.downstream
|
// return to continue node.downstream
|
||||||
return branchJob;
|
return job;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pass control to upper scope by ending current scope
|
// pass control to upper scope by ending current scope
|
||||||
return processor.end(node, branchJob);
|
return processor.exit(branchJob.status);
|
||||||
},
|
},
|
||||||
} as Instruction;
|
} as Instruction;
|
||||||
|
Loading…
Reference in New Issue
Block a user