@nocobase/plugin-workflow 0.10.1-alpha.1 → 0.11.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.d.ts +2 -3
- package/client.js +1 -30
- package/lib/client/AddButton.js +13 -11
- package/lib/client/Branch.js +10 -8
- package/lib/client/CanvasContent.js +12 -10
- package/lib/client/ExecutionCanvas.js +37 -33
- package/lib/client/ExecutionPage.js +4 -9
- package/lib/client/WorkflowCanvas.js +18 -15
- package/lib/client/WorkflowPage.js +4 -9
- package/lib/client/WorkflowProvider.js +1 -40
- package/lib/client/components/CollectionBlockInitializer.js +3 -3
- package/lib/client/components/CollectionFieldset.d.ts +1 -1
- package/lib/client/components/CollectionFieldset.js +15 -16
- package/lib/client/components/Duration.js +5 -5
- package/lib/client/components/DynamicExpression.d.ts +3 -3
- package/lib/client/components/FieldsSelect.d.ts +1 -1
- package/lib/client/components/FieldsSelect.js +10 -7
- package/lib/client/components/NodeDescription.js +45 -31
- package/lib/client/components/RadioWithTooltip.js +13 -20
- package/lib/client/components/ValueBlock.js +14 -21
- package/lib/client/components/renderEngineReference.js +1 -8
- package/lib/client/index.d.ts +12 -4
- package/lib/client/index.js +78 -15
- package/lib/client/locale/zh-CN.d.ts +5 -1
- package/lib/client/locale/zh-CN.js +6 -2
- package/lib/client/nodes/aggregate.d.ts +8 -3
- package/lib/client/nodes/aggregate.js +5 -4
- package/lib/client/nodes/calculation.d.ts +6 -4
- package/lib/client/nodes/calculation.js +22 -28
- package/lib/client/nodes/condition.d.ts +2 -10
- package/lib/client/nodes/condition.js +19 -37
- package/lib/client/nodes/create.d.ts +5 -6
- package/lib/client/nodes/create.js +1 -3
- package/lib/client/nodes/destroy.d.ts +1 -1
- package/lib/client/nodes/index.d.ts +2 -3
- package/lib/client/nodes/index.js +95 -102
- package/lib/client/nodes/loop.d.ts +1 -1
- package/lib/client/nodes/loop.js +46 -54
- package/lib/client/nodes/manual/FormBlockInitializer.js +6 -5
- package/lib/client/nodes/manual/ModeConfig.js +23 -30
- package/lib/client/nodes/manual/SchemaConfig.d.ts +4 -5
- package/lib/client/nodes/manual/SchemaConfig.js +180 -25
- package/lib/client/nodes/manual/WorkflowTodo.js +95 -110
- package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.d.ts +2 -5
- package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.js +6 -5
- package/lib/client/nodes/manual/forms/create.js +8 -1
- package/lib/client/nodes/manual/forms/custom.js +22 -22
- package/lib/client/nodes/manual/forms/update.js +8 -1
- package/lib/client/nodes/manual/index.d.ts +6 -1
- package/lib/client/nodes/manual/index.js +5 -4
- package/lib/client/nodes/parallel.js +23 -20
- package/lib/client/nodes/query.d.ts +3 -5
- package/lib/client/nodes/query.js +1 -3
- package/lib/client/nodes/request.d.ts +2 -2
- package/lib/client/nodes/request.js +7 -7
- package/lib/client/nodes/sql.d.ts +26 -0
- package/lib/client/{triggers/schedule/DateFieldsSelect.js → nodes/sql.js} +37 -46
- package/lib/client/nodes/update.d.ts +2 -2
- package/lib/client/nodes/update.js +1 -1
- package/lib/client/schemas/collection.d.ts +3 -4
- package/lib/client/schemas/collection.js +11 -17
- package/lib/client/style.d.ts +18 -13
- package/lib/client/style.js +315 -292
- package/lib/client/triggers/collection.d.ts +13 -13
- package/lib/client/triggers/collection.js +5 -1
- package/lib/client/triggers/index.d.ts +3 -4
- package/lib/client/triggers/index.js +51 -53
- package/lib/client/triggers/schedule/EndsByField.js +11 -11
- package/lib/client/triggers/schedule/OnField.js +45 -33
- package/lib/client/triggers/schedule/RepeatField.js +4 -4
- package/lib/client/triggers/schedule/ScheduleConfig.js +24 -31
- package/lib/client/triggers/schedule/index.d.ts +1 -1
- package/lib/client/triggers/schedule/index.js +32 -20
- package/lib/client/variable.d.ts +31 -13
- package/lib/client/variable.js +44 -29
- package/lib/server/Plugin.d.ts +3 -6
- package/lib/server/Plugin.js +15 -12
- package/lib/server/Processor.d.ts +3 -5
- package/lib/server/Processor.js +2 -2
- package/lib/server/actions/nodes.js +7 -7
- package/lib/server/fields/expression-field.d.ts +1 -2
- package/lib/server/fields/expression-field.js +1 -8
- package/lib/server/functions/index.d.ts +2 -3
- package/lib/server/index.d.ts +1 -0
- package/lib/server/index.js +12 -0
- package/lib/server/instructions/aggregate.d.ts +1 -1
- package/lib/server/instructions/aggregate.js +5 -5
- package/lib/server/instructions/condition.d.ts +2 -1
- package/lib/server/instructions/create.d.ts +2 -2
- package/lib/server/instructions/create.js +13 -13
- package/lib/server/instructions/delay.d.ts +3 -3
- package/lib/server/instructions/delay.js +66 -64
- package/lib/server/instructions/destroy.d.ts +1 -1
- package/lib/server/instructions/index.d.ts +5 -5
- package/lib/server/instructions/index.js +1 -1
- package/lib/server/instructions/loop.d.ts +1 -2
- package/lib/server/instructions/manual/actions.js +19 -7
- package/lib/server/instructions/manual/forms/create.js +7 -1
- package/lib/server/instructions/manual/forms/index.d.ts +1 -1
- package/lib/server/instructions/manual/forms/update.js +7 -1
- package/lib/server/instructions/manual/index.d.ts +1 -1
- package/lib/server/instructions/parallel.d.ts +1 -2
- package/lib/server/instructions/query.d.ts +1 -1
- package/lib/server/instructions/query.js +8 -1
- package/lib/server/instructions/request.d.ts +3 -3
- package/lib/server/instructions/request.js +5 -2
- package/lib/server/instructions/sql.d.ts +12 -0
- package/lib/server/instructions/sql.js +34 -0
- package/lib/server/instructions/update.d.ts +1 -1
- package/lib/server/migrations/20230221071831-calculation-expression.js +1 -1
- package/lib/server/migrations/20230221121203-condition-calculation.js +1 -1
- package/lib/server/migrations/20230221162902-jsonb-to-json.js +7 -7
- package/lib/server/migrations/20230411034722-manual-multi-form.js +1 -8
- package/lib/server/migrations/20230710115902-manual-action-values.d.ts +4 -0
- package/lib/server/migrations/20230710115902-manual-action-values.js +97 -0
- package/lib/server/triggers/collection.d.ts +1 -1
- package/lib/server/triggers/collection.js +15 -13
- package/lib/server/triggers/index.d.ts +1 -1
- package/lib/server/triggers/schedule.d.ts +1 -1
- package/lib/server/triggers/schedule.js +18 -18
- package/lib/server/{models → types}/Execution.d.ts +2 -3
- package/lib/server/{models → types}/FlowNode.d.ts +1 -2
- package/lib/server/{models → types}/Job.d.ts +1 -2
- package/lib/server/{models → types}/Workflow.d.ts +1 -2
- package/lib/server/types/index.d.ts +4 -0
- package/lib/server/types/index.js +5 -0
- package/lib/server/utils.d.ts +2 -0
- package/lib/server/utils.js +21 -0
- package/package.json +39 -18
- package/server.d.ts +2 -3
- package/server.js +1 -30
- package/src/client/AddButton.tsx +111 -0
- package/src/client/Branch.tsx +37 -0
- package/src/client/CanvasContent.tsx +25 -0
- package/src/client/ExecutionCanvas.tsx +166 -0
- package/src/client/ExecutionLink.tsx +16 -0
- package/src/client/ExecutionPage.tsx +45 -0
- package/src/client/ExecutionResourceProvider.tsx +21 -0
- package/src/client/FlowContext.ts +7 -0
- package/src/client/WorkflowCanvas.tsx +221 -0
- package/src/client/WorkflowLink.tsx +16 -0
- package/src/client/WorkflowPage.tsx +52 -0
- package/src/client/WorkflowProvider.tsx +84 -0
- package/src/client/components/CollectionBlockInitializer.tsx +71 -0
- package/src/client/components/CollectionFieldset.tsx +160 -0
- package/src/client/components/Duration.tsx +45 -0
- package/src/client/components/DynamicExpression.tsx +53 -0
- package/src/client/components/FieldsSelect.tsx +32 -0
- package/src/client/components/FilterDynamicComponent.tsx +15 -0
- package/src/client/components/NodeDescription.tsx +51 -0
- package/src/client/components/NullRender.tsx +3 -0
- package/src/client/components/OpenDrawer.tsx +24 -0
- package/src/client/components/RadioWithTooltip.tsx +38 -0
- package/src/client/components/ValueBlock.tsx +67 -0
- package/src/client/components/renderEngineReference.tsx +30 -0
- package/src/client/constants.tsx +91 -0
- package/src/client/index.tsx +51 -0
- package/src/client/interfaces/expression.tsx +25 -0
- package/src/client/locale/en-US.ts +136 -0
- package/src/client/locale/es-ES.ts +129 -0
- package/src/client/locale/index.ts +18 -0
- package/src/client/locale/ja-JP.ts +90 -0
- package/src/client/locale/pt-BR.ts +136 -0
- package/src/client/locale/ru-RU.ts +90 -0
- package/src/client/locale/tr-TR.ts +90 -0
- package/src/client/locale/zh-CN.ts +248 -0
- package/src/client/nodes/aggregate.tsx +327 -0
- package/src/client/nodes/calculation.tsx +216 -0
- package/src/client/nodes/condition.tsx +463 -0
- package/src/client/nodes/create.tsx +85 -0
- package/src/client/nodes/delay.tsx +37 -0
- package/src/client/nodes/destroy.tsx +34 -0
- package/src/client/nodes/index.tsx +485 -0
- package/src/client/nodes/loop.tsx +144 -0
- package/src/client/nodes/manual/AssigneesSelect.tsx +33 -0
- package/src/client/nodes/manual/DetailsBlockProvider.tsx +80 -0
- package/src/client/nodes/manual/FormBlockInitializer.tsx +69 -0
- package/src/client/nodes/manual/FormBlockProvider.tsx +75 -0
- package/src/client/nodes/manual/ModeConfig.tsx +84 -0
- package/src/client/nodes/manual/SchemaConfig.tsx +509 -0
- package/src/client/nodes/manual/WorkflowTodo.tsx +607 -0
- package/src/client/nodes/manual/WorkflowTodoBlockInitializer.tsx +28 -0
- package/src/client/nodes/manual/forms/create.tsx +92 -0
- package/src/client/nodes/manual/forms/custom.tsx +392 -0
- package/src/client/nodes/manual/forms/update.tsx +134 -0
- package/src/client/nodes/manual/index.tsx +162 -0
- package/src/client/nodes/manual/utils.ts +28 -0
- package/src/client/nodes/parallel.tsx +138 -0
- package/src/client/nodes/query.tsx +88 -0
- package/src/client/nodes/request.tsx +185 -0
- package/src/client/nodes/sql.tsx +37 -0
- package/src/client/nodes/update.tsx +99 -0
- package/src/client/schemas/collection.ts +75 -0
- package/src/client/schemas/executions.tsx +169 -0
- package/src/client/schemas/workflows.ts +364 -0
- package/src/client/style.tsx +347 -0
- package/src/client/triggers/collection.tsx +190 -0
- package/src/client/triggers/index.tsx +311 -0
- package/src/client/triggers/schedule/EndsByField.tsx +40 -0
- package/src/client/triggers/schedule/OnField.tsx +64 -0
- package/src/client/triggers/schedule/RepeatField.tsx +116 -0
- package/src/client/triggers/schedule/ScheduleConfig.tsx +227 -0
- package/src/client/triggers/schedule/constants.ts +4 -0
- package/src/client/triggers/schedule/index.tsx +78 -0
- package/src/client/triggers/schedule/locale/Cron.zh-CN.ts +79 -0
- package/src/client/utils.ts +36 -0
- package/src/client/variable.tsx +318 -0
- package/src/index.ts +1 -0
- package/src/server/Plugin.ts +355 -0
- package/src/server/Processor.ts +354 -0
- package/src/server/__tests__/Plugin.test.ts +398 -0
- package/src/server/__tests__/Processor.test.ts +474 -0
- package/src/server/__tests__/actions/workflows.test.ts +419 -0
- package/src/server/__tests__/collections/categories.ts +27 -0
- package/src/server/__tests__/collections/comments.ts +24 -0
- package/src/server/__tests__/collections/posts.ts +42 -0
- package/src/server/__tests__/collections/replies.ts +9 -0
- package/src/server/__tests__/collections/tags.ts +15 -0
- package/src/server/__tests__/index.ts +89 -0
- package/src/server/__tests__/instructions/aggregate.test.ts +294 -0
- package/src/server/__tests__/instructions/calculation.test.ts +265 -0
- package/src/server/__tests__/instructions/condition.test.ts +335 -0
- package/src/server/__tests__/instructions/create.test.ts +129 -0
- package/src/server/__tests__/instructions/delay.test.ts +182 -0
- package/src/server/__tests__/instructions/destroy.test.ts +58 -0
- package/src/server/__tests__/instructions/loop.test.ts +331 -0
- package/src/server/__tests__/instructions/manual.test.ts +1173 -0
- package/src/server/__tests__/instructions/parallel.test.ts +445 -0
- package/src/server/__tests__/instructions/query.test.ts +359 -0
- package/src/server/__tests__/instructions/request.test.ts +247 -0
- package/src/server/__tests__/instructions/sql.test.ts +162 -0
- package/src/server/__tests__/instructions/update.test.ts +189 -0
- package/src/server/__tests__/triggers/collection.test.ts +333 -0
- package/src/server/__tests__/triggers/schedule.test.ts +369 -0
- package/src/server/actions/index.ts +25 -0
- package/src/server/actions/nodes.ts +214 -0
- package/src/server/actions/workflows.ts +178 -0
- package/src/server/collections/executions.ts +35 -0
- package/src/server/collections/flow_nodes.ts +54 -0
- package/src/server/collections/jobs.ts +31 -0
- package/src/server/collections/workflows.ts +88 -0
- package/src/server/constants.ts +26 -0
- package/src/server/fields/expression-field.ts +11 -0
- package/src/server/fields/index.ts +7 -0
- package/src/server/functions/index.ts +16 -0
- package/src/server/index.ts +6 -0
- package/src/server/instructions/aggregate.ts +42 -0
- package/src/server/instructions/calculation.ts +41 -0
- package/src/server/instructions/condition.ts +172 -0
- package/src/server/instructions/create.ts +39 -0
- package/src/server/instructions/delay.ts +105 -0
- package/src/server/instructions/destroy.ts +23 -0
- package/src/server/instructions/index.ts +64 -0
- package/src/server/instructions/loop.ts +99 -0
- package/src/server/instructions/manual/actions.ts +91 -0
- package/src/server/instructions/manual/collecions/jobs.ts +17 -0
- package/src/server/instructions/manual/collecions/users.ts +15 -0
- package/src/server/instructions/manual/collecions/users_jobs.ts +50 -0
- package/src/server/instructions/manual/forms/create.ts +23 -0
- package/src/server/instructions/manual/forms/index.ts +12 -0
- package/src/server/instructions/manual/forms/update.ts +23 -0
- package/src/server/instructions/manual/index.ts +184 -0
- package/src/server/instructions/parallel.ts +121 -0
- package/src/server/instructions/query.ts +42 -0
- package/src/server/instructions/request.ts +88 -0
- package/src/server/instructions/sql.ts +25 -0
- package/src/server/instructions/update.ts +24 -0
- package/src/server/migrations/20221129153547-calculation-variables.ts +64 -0
- package/src/server/migrations/20230221032941-change-request-body-type.ts +76 -0
- package/src/server/migrations/20230221071831-calculation-expression.ts +102 -0
- package/src/server/migrations/20230221121203-condition-calculation.ts +82 -0
- package/src/server/migrations/20230221162902-jsonb-to-json.ts +51 -0
- package/src/server/migrations/20230411034722-manual-multi-form.ts +282 -0
- package/src/server/migrations/20230612021134-manual-collection-block.ts +138 -0
- package/src/server/migrations/20230710115902-manual-action-values.ts +78 -0
- package/src/server/triggers/collection.ts +146 -0
- package/src/server/triggers/index.ts +22 -0
- package/src/server/triggers/schedule.ts +567 -0
- package/src/server/types/Execution.ts +26 -0
- package/src/server/types/FlowNode.ts +21 -0
- package/src/server/types/Job.ts +18 -0
- package/src/server/types/Workflow.ts +36 -0
- package/src/server/types/index.ts +4 -0
- package/src/server/utils.ts +17 -0
- package/lib/client/triggers/schedule/DateFieldsSelect.d.ts +0 -2
- /package/lib/server/{models → types}/Execution.js +0 -0
- /package/lib/server/{models → types}/FlowNode.js +0 -0
- /package/lib/server/{models → types}/Job.js +0 -0
- /package/lib/server/{models → types}/Workflow.js +0 -0
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import Database from '@nocobase/database';
|
|
2
|
+
import { Application } from '@nocobase/server';
|
|
3
|
+
import { getApp, sleep } from '..';
|
|
4
|
+
import { EXECUTION_STATUS, JOB_STATUS } from '../../constants';
|
|
5
|
+
|
|
6
|
+
describe('workflow > instructions > parallel', () => {
|
|
7
|
+
let app: Application;
|
|
8
|
+
let db: Database;
|
|
9
|
+
let PostRepo;
|
|
10
|
+
let WorkflowModel;
|
|
11
|
+
let workflow;
|
|
12
|
+
let plugin;
|
|
13
|
+
|
|
14
|
+
beforeEach(async () => {
|
|
15
|
+
app = await getApp();
|
|
16
|
+
plugin = app.pm.get('workflow');
|
|
17
|
+
|
|
18
|
+
db = app.db;
|
|
19
|
+
WorkflowModel = db.getCollection('workflows').model;
|
|
20
|
+
PostRepo = db.getCollection('posts').repository;
|
|
21
|
+
|
|
22
|
+
workflow = await WorkflowModel.create({
|
|
23
|
+
enabled: true,
|
|
24
|
+
type: 'collection',
|
|
25
|
+
config: {
|
|
26
|
+
mode: 1,
|
|
27
|
+
collection: 'posts',
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => app.stop());
|
|
33
|
+
|
|
34
|
+
describe('single all', () => {
|
|
35
|
+
it('all resolved', async () => {
|
|
36
|
+
const n1 = await workflow.createNode({
|
|
37
|
+
type: 'parallel',
|
|
38
|
+
});
|
|
39
|
+
const n2 = await workflow.createNode({
|
|
40
|
+
type: 'echo',
|
|
41
|
+
upstreamId: n1.id,
|
|
42
|
+
branchIndex: 0,
|
|
43
|
+
});
|
|
44
|
+
const n3 = await workflow.createNode({
|
|
45
|
+
type: 'echo',
|
|
46
|
+
upstreamId: n1.id,
|
|
47
|
+
branchIndex: 1,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
51
|
+
|
|
52
|
+
await sleep(500);
|
|
53
|
+
|
|
54
|
+
const [execution] = await workflow.getExecutions();
|
|
55
|
+
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
56
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
57
|
+
expect(jobs.length).toBe(3);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('some rejected', async () => {
|
|
61
|
+
const n1 = await workflow.createNode({
|
|
62
|
+
type: 'parallel',
|
|
63
|
+
});
|
|
64
|
+
const n2 = await workflow.createNode({
|
|
65
|
+
type: 'echo',
|
|
66
|
+
upstreamId: n1.id,
|
|
67
|
+
branchIndex: 0,
|
|
68
|
+
});
|
|
69
|
+
const n3 = await workflow.createNode({
|
|
70
|
+
type: 'error',
|
|
71
|
+
upstreamId: n1.id,
|
|
72
|
+
branchIndex: 1,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
76
|
+
|
|
77
|
+
await sleep(500);
|
|
78
|
+
|
|
79
|
+
const [execution] = await workflow.getExecutions();
|
|
80
|
+
expect(execution.status).toBe(EXECUTION_STATUS.ERROR);
|
|
81
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
82
|
+
expect(jobs.length).toBe(3);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('first branch rejected', async () => {
|
|
86
|
+
const n1 = await workflow.createNode({
|
|
87
|
+
type: 'parallel',
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const n2 = await workflow.createNode({
|
|
91
|
+
type: 'error',
|
|
92
|
+
upstreamId: n1.id,
|
|
93
|
+
branchIndex: 0,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const n3 = await workflow.createNode({
|
|
97
|
+
type: 'echo',
|
|
98
|
+
upstreamId: n1.id,
|
|
99
|
+
branchIndex: 1,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
103
|
+
|
|
104
|
+
await sleep(500);
|
|
105
|
+
|
|
106
|
+
const [execution] = await workflow.getExecutions();
|
|
107
|
+
expect(execution.status).toBe(EXECUTION_STATUS.ERROR);
|
|
108
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
109
|
+
expect(jobs.length).toBe(2);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe('single any', () => {
|
|
114
|
+
it('first resolved', async () => {
|
|
115
|
+
const n1 = await workflow.createNode({
|
|
116
|
+
type: 'parallel',
|
|
117
|
+
config: {
|
|
118
|
+
mode: 'any',
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
const n2 = await workflow.createNode({
|
|
122
|
+
type: 'echo',
|
|
123
|
+
upstreamId: n1.id,
|
|
124
|
+
branchIndex: 0,
|
|
125
|
+
});
|
|
126
|
+
const n3 = await workflow.createNode({
|
|
127
|
+
type: 'error',
|
|
128
|
+
upstreamId: n1.id,
|
|
129
|
+
branchIndex: 1,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
133
|
+
|
|
134
|
+
await sleep(500);
|
|
135
|
+
|
|
136
|
+
const [execution] = await workflow.getExecutions();
|
|
137
|
+
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
138
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
139
|
+
expect(jobs.length).toBe(2);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('first rejected', async () => {
|
|
143
|
+
const n1 = await workflow.createNode({
|
|
144
|
+
type: 'parallel',
|
|
145
|
+
config: {
|
|
146
|
+
mode: 'any',
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
const n2 = await workflow.createNode({
|
|
150
|
+
type: 'error',
|
|
151
|
+
upstreamId: n1.id,
|
|
152
|
+
branchIndex: 0,
|
|
153
|
+
});
|
|
154
|
+
const n3 = await workflow.createNode({
|
|
155
|
+
type: 'echo',
|
|
156
|
+
upstreamId: n1.id,
|
|
157
|
+
branchIndex: 1,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
161
|
+
|
|
162
|
+
await sleep(500);
|
|
163
|
+
|
|
164
|
+
const [execution] = await workflow.getExecutions();
|
|
165
|
+
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
166
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
167
|
+
expect(jobs.length).toBe(3);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('all rejected', async () => {
|
|
171
|
+
const n1 = await workflow.createNode({
|
|
172
|
+
type: 'parallel',
|
|
173
|
+
config: {
|
|
174
|
+
mode: 'any',
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
const n2 = await workflow.createNode({
|
|
178
|
+
type: 'error',
|
|
179
|
+
upstreamId: n1.id,
|
|
180
|
+
branchIndex: 0,
|
|
181
|
+
});
|
|
182
|
+
const n3 = await workflow.createNode({
|
|
183
|
+
type: 'error',
|
|
184
|
+
upstreamId: n1.id,
|
|
185
|
+
branchIndex: 1,
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
189
|
+
|
|
190
|
+
await sleep(500);
|
|
191
|
+
|
|
192
|
+
const [execution] = await workflow.getExecutions();
|
|
193
|
+
expect(execution.status).toBe(EXECUTION_STATUS.FAILED);
|
|
194
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
195
|
+
expect(jobs.length).toBe(3);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe('single race', () => {
|
|
200
|
+
it('first resolved', async () => {
|
|
201
|
+
const n1 = await workflow.createNode({
|
|
202
|
+
type: 'parallel',
|
|
203
|
+
config: {
|
|
204
|
+
mode: 'race',
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
const n2 = await workflow.createNode({
|
|
208
|
+
type: 'echo',
|
|
209
|
+
upstreamId: n1.id,
|
|
210
|
+
branchIndex: 0,
|
|
211
|
+
});
|
|
212
|
+
const n3 = await workflow.createNode({
|
|
213
|
+
type: 'error',
|
|
214
|
+
upstreamId: n1.id,
|
|
215
|
+
branchIndex: 1,
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
219
|
+
|
|
220
|
+
await sleep(500);
|
|
221
|
+
|
|
222
|
+
const [execution] = await workflow.getExecutions();
|
|
223
|
+
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
224
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
225
|
+
expect(jobs.length).toBe(2);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('first rejected', async () => {
|
|
229
|
+
const n1 = await workflow.createNode({
|
|
230
|
+
type: 'parallel',
|
|
231
|
+
config: {
|
|
232
|
+
mode: 'race',
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
const n2 = await workflow.createNode({
|
|
236
|
+
type: 'error',
|
|
237
|
+
upstreamId: n1.id,
|
|
238
|
+
branchIndex: 0,
|
|
239
|
+
});
|
|
240
|
+
const n3 = await workflow.createNode({
|
|
241
|
+
type: 'echo',
|
|
242
|
+
upstreamId: n1.id,
|
|
243
|
+
branchIndex: 1,
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
247
|
+
|
|
248
|
+
await sleep(500);
|
|
249
|
+
|
|
250
|
+
const [execution] = await workflow.getExecutions();
|
|
251
|
+
expect(execution.status).toBe(EXECUTION_STATUS.ERROR);
|
|
252
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
253
|
+
expect(jobs.length).toBe(2);
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
describe('branch and join', () => {
|
|
258
|
+
it('link to single branch', async () => {
|
|
259
|
+
const n1 = await workflow.createNode({
|
|
260
|
+
type: 'parallel',
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
const n2 = await workflow.createNode({
|
|
264
|
+
title: 'echo1',
|
|
265
|
+
type: 'echo',
|
|
266
|
+
upstreamId: n1.id,
|
|
267
|
+
branchIndex: 0,
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
const n3 = await workflow.createNode({
|
|
271
|
+
title: 'echo2',
|
|
272
|
+
type: 'echo',
|
|
273
|
+
upstreamId: n1.id,
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
await n1.setDownstream(n3);
|
|
277
|
+
|
|
278
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
279
|
+
|
|
280
|
+
await sleep(500);
|
|
281
|
+
|
|
282
|
+
const [execution] = await workflow.getExecutions();
|
|
283
|
+
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
284
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
285
|
+
expect(jobs.length).toBe(3);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it('link to multipe branches', async () => {
|
|
289
|
+
const n1 = await workflow.createNode({
|
|
290
|
+
type: 'parallel',
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
const n2 = await workflow.createNode({
|
|
294
|
+
title: 'echo1',
|
|
295
|
+
type: 'echo',
|
|
296
|
+
upstreamId: n1.id,
|
|
297
|
+
branchIndex: 0,
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
const n3 = await workflow.createNode({
|
|
301
|
+
title: 'echo2',
|
|
302
|
+
type: 'echo',
|
|
303
|
+
upstreamId: n1.id,
|
|
304
|
+
branchIndex: 1,
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
const n4 = await workflow.createNode({
|
|
308
|
+
title: 'echo on end',
|
|
309
|
+
type: 'echo',
|
|
310
|
+
upstreamId: n1.id,
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
await n1.setDownstream(n4);
|
|
314
|
+
|
|
315
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
316
|
+
|
|
317
|
+
await sleep(500);
|
|
318
|
+
|
|
319
|
+
const [execution] = await workflow.getExecutions();
|
|
320
|
+
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
321
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
322
|
+
expect(jobs.length).toBe(4);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it('random branch index', async () => {
|
|
326
|
+
const n1 = await workflow.createNode({
|
|
327
|
+
type: 'parallel',
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
const n2 = await workflow.createNode({
|
|
331
|
+
title: 'echo1',
|
|
332
|
+
type: 'echo',
|
|
333
|
+
upstreamId: n1.id,
|
|
334
|
+
branchIndex: 3,
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
const n3 = await workflow.createNode({
|
|
338
|
+
title: 'echo2',
|
|
339
|
+
type: 'echo',
|
|
340
|
+
upstreamId: n1.id,
|
|
341
|
+
branchIndex: 1,
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
345
|
+
|
|
346
|
+
await sleep(500);
|
|
347
|
+
|
|
348
|
+
const [execution] = await workflow.getExecutions();
|
|
349
|
+
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
350
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
351
|
+
expect(jobs.length).toBe(3);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it('downstream has manual node', async () => {
|
|
355
|
+
const n1 = await workflow.createNode({
|
|
356
|
+
type: 'parallel',
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
const n2 = await workflow.createNode({
|
|
360
|
+
title: 'manual',
|
|
361
|
+
type: 'manual',
|
|
362
|
+
upstreamId: n1.id,
|
|
363
|
+
branchIndex: 0,
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
const n3 = await workflow.createNode({
|
|
367
|
+
title: 'echo',
|
|
368
|
+
type: 'echo',
|
|
369
|
+
upstreamId: n1.id,
|
|
370
|
+
branchIndex: 1,
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
const n4 = await workflow.createNode({
|
|
374
|
+
title: 'echo on end',
|
|
375
|
+
type: 'echo',
|
|
376
|
+
upstreamId: n1.id,
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
await n1.setDownstream(n4);
|
|
380
|
+
|
|
381
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
382
|
+
|
|
383
|
+
await sleep(500);
|
|
384
|
+
|
|
385
|
+
const [e1] = await workflow.getExecutions();
|
|
386
|
+
expect(e1.status).toBe(EXECUTION_STATUS.STARTED);
|
|
387
|
+
|
|
388
|
+
const [pending] = await e1.getJobs({ where: { nodeId: n2.id } });
|
|
389
|
+
pending.set({
|
|
390
|
+
status: JOB_STATUS.RESOLVED,
|
|
391
|
+
result: 123,
|
|
392
|
+
});
|
|
393
|
+
pending.execution = e1;
|
|
394
|
+
plugin.resume(pending);
|
|
395
|
+
|
|
396
|
+
await sleep(500);
|
|
397
|
+
|
|
398
|
+
const [e2] = await workflow.getExecutions();
|
|
399
|
+
expect(e2.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
400
|
+
const jobs = await e2.getJobs({ order: [['id', 'ASC']] });
|
|
401
|
+
expect(jobs.length).toBe(4);
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
describe('nested', () => {
|
|
406
|
+
it('nested 2 levels', async () => {
|
|
407
|
+
const n1 = await workflow.createNode({
|
|
408
|
+
type: 'parallel',
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
const n2 = await workflow.createNode({
|
|
412
|
+
type: 'parallel',
|
|
413
|
+
upstreamId: n1.id,
|
|
414
|
+
branchIndex: 0,
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
const n3 = await workflow.createNode({
|
|
418
|
+
type: 'echo',
|
|
419
|
+
upstreamId: n1.id,
|
|
420
|
+
branchIndex: 1,
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
const n4 = await workflow.createNode({
|
|
424
|
+
type: 'echo',
|
|
425
|
+
upstreamId: n2.id,
|
|
426
|
+
branchIndex: 0,
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
const n5 = await workflow.createNode({
|
|
430
|
+
type: 'echo',
|
|
431
|
+
upstreamId: n1.id,
|
|
432
|
+
});
|
|
433
|
+
await n1.setDownstream(n5);
|
|
434
|
+
|
|
435
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
436
|
+
|
|
437
|
+
await sleep(500);
|
|
438
|
+
|
|
439
|
+
const [execution] = await workflow.getExecutions();
|
|
440
|
+
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
441
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
442
|
+
expect(jobs.length).toBe(5);
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
});
|