@nocobase/plugin-workflow-parallel 0.17.0-alpha.4
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/LICENSE +661 -0
- package/README.md +9 -0
- package/README.zh-CN.md +9 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/ParallelInstruction.d.ts +30 -0
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.js +21 -0
- package/dist/externalVersion.js +9 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/locale/en-US.json +11 -0
- package/dist/locale/es-ES.json +10 -0
- package/dist/locale/fr-FR.json +10 -0
- package/dist/locale/index.d.ts +3 -0
- package/dist/locale/index.js +39 -0
- package/dist/locale/ja-JP.json +7 -0
- package/dist/locale/pt-BR.json +10 -0
- package/dist/locale/ru-RU.json +7 -0
- package/dist/locale/tr-TR.json +7 -0
- package/dist/locale/zh-CN.json +11 -0
- package/dist/server/ParallelInstruction.d.ts +10 -0
- package/dist/server/ParallelInstruction.js +124 -0
- package/dist/server/Plugin.d.ts +6 -0
- package/dist/server/Plugin.js +42 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +33 -0
- package/package.json +25 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
- package/src/client/ParallelInstruction.tsx +147 -0
- package/src/client/index.ts +19 -0
- package/src/index.ts +2 -0
- package/src/locale/en-US.json +11 -0
- package/src/locale/es-ES.json +10 -0
- package/src/locale/fr-FR.json +10 -0
- package/src/locale/index.ts +12 -0
- package/src/locale/ja-JP.json +7 -0
- package/src/locale/pt-BR.json +10 -0
- package/src/locale/ru-RU.json +7 -0
- package/src/locale/tr-TR.json +7 -0
- package/src/locale/zh-CN.json +11 -0
- package/src/server/ParallelInstruction.ts +119 -0
- package/src/server/Plugin.ts +14 -0
- package/src/server/__tests__/instruction.test.ts +560 -0
- package/src/server/index.ts +1 -0
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
import Database from '@nocobase/database';
|
|
2
|
+
import { Application } from '@nocobase/server';
|
|
3
|
+
import { BRANCH_INDEX, EXECUTION_STATUS, JOB_STATUS } from '@nocobase/plugin-workflow';
|
|
4
|
+
import { getApp, sleep } from '@nocobase/plugin-workflow-test';
|
|
5
|
+
|
|
6
|
+
import Plugin from '..';
|
|
7
|
+
|
|
8
|
+
describe('workflow > instructions > parallel', () => {
|
|
9
|
+
let app: Application;
|
|
10
|
+
let db: Database;
|
|
11
|
+
let PostRepo;
|
|
12
|
+
let WorkflowModel;
|
|
13
|
+
let workflow;
|
|
14
|
+
let plugin;
|
|
15
|
+
|
|
16
|
+
beforeEach(async () => {
|
|
17
|
+
app = await getApp({
|
|
18
|
+
plugins: [Plugin],
|
|
19
|
+
});
|
|
20
|
+
plugin = app.pm.get('workflow');
|
|
21
|
+
|
|
22
|
+
db = app.db;
|
|
23
|
+
WorkflowModel = db.getCollection('workflows').model;
|
|
24
|
+
PostRepo = db.getCollection('posts').repository;
|
|
25
|
+
|
|
26
|
+
workflow = await WorkflowModel.create({
|
|
27
|
+
enabled: true,
|
|
28
|
+
type: 'collection',
|
|
29
|
+
config: {
|
|
30
|
+
mode: 1,
|
|
31
|
+
collection: 'posts',
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
afterEach(() => app.destroy());
|
|
37
|
+
|
|
38
|
+
describe('single all', () => {
|
|
39
|
+
it('all resolved', async () => {
|
|
40
|
+
const n1 = await workflow.createNode({
|
|
41
|
+
type: 'parallel',
|
|
42
|
+
});
|
|
43
|
+
const n2 = await workflow.createNode({
|
|
44
|
+
type: 'echo',
|
|
45
|
+
upstreamId: n1.id,
|
|
46
|
+
branchIndex: 0,
|
|
47
|
+
});
|
|
48
|
+
const n3 = await workflow.createNode({
|
|
49
|
+
type: 'echo',
|
|
50
|
+
upstreamId: n1.id,
|
|
51
|
+
branchIndex: 1,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
55
|
+
|
|
56
|
+
await sleep(500);
|
|
57
|
+
|
|
58
|
+
const [execution] = await workflow.getExecutions();
|
|
59
|
+
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
60
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
61
|
+
expect(jobs.length).toBe(3);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('some rejected', async () => {
|
|
65
|
+
const n1 = await workflow.createNode({
|
|
66
|
+
type: 'parallel',
|
|
67
|
+
});
|
|
68
|
+
const n2 = await workflow.createNode({
|
|
69
|
+
type: 'echo',
|
|
70
|
+
upstreamId: n1.id,
|
|
71
|
+
branchIndex: 0,
|
|
72
|
+
});
|
|
73
|
+
const n3 = await workflow.createNode({
|
|
74
|
+
type: 'error',
|
|
75
|
+
upstreamId: n1.id,
|
|
76
|
+
branchIndex: 1,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
80
|
+
|
|
81
|
+
await sleep(500);
|
|
82
|
+
|
|
83
|
+
const [execution] = await workflow.getExecutions();
|
|
84
|
+
expect(execution.status).toBe(EXECUTION_STATUS.ERROR);
|
|
85
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
86
|
+
expect(jobs.length).toBe(3);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('first branch rejected', async () => {
|
|
90
|
+
const n1 = await workflow.createNode({
|
|
91
|
+
type: 'parallel',
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const n2 = await workflow.createNode({
|
|
95
|
+
type: 'error',
|
|
96
|
+
upstreamId: n1.id,
|
|
97
|
+
branchIndex: 0,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const n3 = await workflow.createNode({
|
|
101
|
+
type: 'echo',
|
|
102
|
+
upstreamId: n1.id,
|
|
103
|
+
branchIndex: 1,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
107
|
+
|
|
108
|
+
await sleep(500);
|
|
109
|
+
|
|
110
|
+
const [execution] = await workflow.getExecutions();
|
|
111
|
+
expect(execution.status).toBe(EXECUTION_STATUS.ERROR);
|
|
112
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
113
|
+
expect(jobs.length).toBe(2);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe('single any', () => {
|
|
118
|
+
it('first resolved', async () => {
|
|
119
|
+
const n1 = await workflow.createNode({
|
|
120
|
+
type: 'parallel',
|
|
121
|
+
config: {
|
|
122
|
+
mode: 'any',
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
const n2 = await workflow.createNode({
|
|
126
|
+
type: 'echo',
|
|
127
|
+
upstreamId: n1.id,
|
|
128
|
+
branchIndex: 0,
|
|
129
|
+
});
|
|
130
|
+
const n3 = await workflow.createNode({
|
|
131
|
+
type: 'error',
|
|
132
|
+
upstreamId: n1.id,
|
|
133
|
+
branchIndex: 1,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
137
|
+
|
|
138
|
+
await sleep(500);
|
|
139
|
+
|
|
140
|
+
const [execution] = await workflow.getExecutions();
|
|
141
|
+
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
142
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
143
|
+
expect(jobs.length).toBe(2);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('first rejected', async () => {
|
|
147
|
+
const n1 = await workflow.createNode({
|
|
148
|
+
type: 'parallel',
|
|
149
|
+
config: {
|
|
150
|
+
mode: 'any',
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
const n2 = await workflow.createNode({
|
|
154
|
+
type: 'error',
|
|
155
|
+
upstreamId: n1.id,
|
|
156
|
+
branchIndex: 0,
|
|
157
|
+
});
|
|
158
|
+
const n3 = await workflow.createNode({
|
|
159
|
+
type: 'echo',
|
|
160
|
+
upstreamId: n1.id,
|
|
161
|
+
branchIndex: 1,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
165
|
+
|
|
166
|
+
await sleep(500);
|
|
167
|
+
|
|
168
|
+
const [execution] = await workflow.getExecutions();
|
|
169
|
+
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
170
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
171
|
+
expect(jobs.length).toBe(3);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('all rejected', async () => {
|
|
175
|
+
const n1 = await workflow.createNode({
|
|
176
|
+
type: 'parallel',
|
|
177
|
+
config: {
|
|
178
|
+
mode: 'any',
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
const n2 = await workflow.createNode({
|
|
182
|
+
type: 'error',
|
|
183
|
+
upstreamId: n1.id,
|
|
184
|
+
branchIndex: 0,
|
|
185
|
+
});
|
|
186
|
+
const n3 = await workflow.createNode({
|
|
187
|
+
type: 'error',
|
|
188
|
+
upstreamId: n1.id,
|
|
189
|
+
branchIndex: 1,
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
193
|
+
|
|
194
|
+
await sleep(500);
|
|
195
|
+
|
|
196
|
+
const [execution] = await workflow.getExecutions();
|
|
197
|
+
expect(execution.status).toBe(EXECUTION_STATUS.FAILED);
|
|
198
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
199
|
+
expect(jobs.length).toBe(3);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
describe('single race', () => {
|
|
204
|
+
it('first resolved', async () => {
|
|
205
|
+
const n1 = await workflow.createNode({
|
|
206
|
+
type: 'parallel',
|
|
207
|
+
config: {
|
|
208
|
+
mode: 'race',
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
const n2 = await workflow.createNode({
|
|
212
|
+
type: 'echo',
|
|
213
|
+
upstreamId: n1.id,
|
|
214
|
+
branchIndex: 0,
|
|
215
|
+
});
|
|
216
|
+
const n3 = await workflow.createNode({
|
|
217
|
+
type: 'error',
|
|
218
|
+
upstreamId: n1.id,
|
|
219
|
+
branchIndex: 1,
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
223
|
+
|
|
224
|
+
await sleep(500);
|
|
225
|
+
|
|
226
|
+
const [execution] = await workflow.getExecutions();
|
|
227
|
+
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
228
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
229
|
+
expect(jobs.length).toBe(2);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('first rejected', async () => {
|
|
233
|
+
const n1 = await workflow.createNode({
|
|
234
|
+
type: 'parallel',
|
|
235
|
+
config: {
|
|
236
|
+
mode: 'race',
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
const n2 = await workflow.createNode({
|
|
240
|
+
type: 'error',
|
|
241
|
+
upstreamId: n1.id,
|
|
242
|
+
branchIndex: 0,
|
|
243
|
+
});
|
|
244
|
+
const n3 = await workflow.createNode({
|
|
245
|
+
type: 'echo',
|
|
246
|
+
upstreamId: n1.id,
|
|
247
|
+
branchIndex: 1,
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
251
|
+
|
|
252
|
+
await sleep(500);
|
|
253
|
+
|
|
254
|
+
const [execution] = await workflow.getExecutions();
|
|
255
|
+
expect(execution.status).toBe(EXECUTION_STATUS.ERROR);
|
|
256
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
257
|
+
expect(jobs.length).toBe(2);
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
describe('branch and join', () => {
|
|
262
|
+
it('link to single branch', async () => {
|
|
263
|
+
const n1 = await workflow.createNode({
|
|
264
|
+
type: 'parallel',
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
const n2 = await workflow.createNode({
|
|
268
|
+
title: 'echo1',
|
|
269
|
+
type: 'echo',
|
|
270
|
+
upstreamId: n1.id,
|
|
271
|
+
branchIndex: 0,
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
const n3 = await workflow.createNode({
|
|
275
|
+
title: 'echo2',
|
|
276
|
+
type: 'echo',
|
|
277
|
+
upstreamId: n1.id,
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
await n1.setDownstream(n3);
|
|
281
|
+
|
|
282
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
283
|
+
|
|
284
|
+
await sleep(500);
|
|
285
|
+
|
|
286
|
+
const [execution] = await workflow.getExecutions();
|
|
287
|
+
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
288
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
289
|
+
expect(jobs.length).toBe(3);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it('link to multipe branches', async () => {
|
|
293
|
+
const n1 = await workflow.createNode({
|
|
294
|
+
type: 'parallel',
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
const n2 = await workflow.createNode({
|
|
298
|
+
title: 'echo1',
|
|
299
|
+
type: 'echo',
|
|
300
|
+
upstreamId: n1.id,
|
|
301
|
+
branchIndex: 0,
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
const n3 = await workflow.createNode({
|
|
305
|
+
title: 'echo2',
|
|
306
|
+
type: 'echo',
|
|
307
|
+
upstreamId: n1.id,
|
|
308
|
+
branchIndex: 1,
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
const n4 = await workflow.createNode({
|
|
312
|
+
title: 'echo on end',
|
|
313
|
+
type: 'echo',
|
|
314
|
+
upstreamId: n1.id,
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
await n1.setDownstream(n4);
|
|
318
|
+
|
|
319
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
320
|
+
|
|
321
|
+
await sleep(500);
|
|
322
|
+
|
|
323
|
+
const [execution] = await workflow.getExecutions();
|
|
324
|
+
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
325
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
326
|
+
expect(jobs.length).toBe(4);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it('random branch index', async () => {
|
|
330
|
+
const n1 = await workflow.createNode({
|
|
331
|
+
type: 'parallel',
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
const n2 = await workflow.createNode({
|
|
335
|
+
title: 'echo1',
|
|
336
|
+
type: 'echo',
|
|
337
|
+
upstreamId: n1.id,
|
|
338
|
+
branchIndex: 3,
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
const n3 = await workflow.createNode({
|
|
342
|
+
title: 'echo2',
|
|
343
|
+
type: 'echo',
|
|
344
|
+
upstreamId: n1.id,
|
|
345
|
+
branchIndex: 1,
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
349
|
+
|
|
350
|
+
await sleep(500);
|
|
351
|
+
|
|
352
|
+
const [execution] = await workflow.getExecutions();
|
|
353
|
+
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
354
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
355
|
+
expect(jobs.length).toBe(3);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it('downstream has manual node', async () => {
|
|
359
|
+
const n1 = await workflow.createNode({
|
|
360
|
+
type: 'parallel',
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
const n2 = await workflow.createNode({
|
|
364
|
+
type: 'prompt',
|
|
365
|
+
upstreamId: n1.id,
|
|
366
|
+
branchIndex: 0,
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
const n3 = await workflow.createNode({
|
|
370
|
+
type: 'echo',
|
|
371
|
+
upstreamId: n1.id,
|
|
372
|
+
branchIndex: 1,
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
const n4 = await workflow.createNode({
|
|
376
|
+
type: 'echo',
|
|
377
|
+
upstreamId: n1.id,
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
await n1.setDownstream(n4);
|
|
381
|
+
|
|
382
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
383
|
+
|
|
384
|
+
await sleep(500);
|
|
385
|
+
|
|
386
|
+
const [e1] = await workflow.getExecutions();
|
|
387
|
+
expect(e1.status).toBe(EXECUTION_STATUS.STARTED);
|
|
388
|
+
|
|
389
|
+
const [pending] = await e1.getJobs({ where: { nodeId: n2.id } });
|
|
390
|
+
pending.set({
|
|
391
|
+
status: JOB_STATUS.RESOLVED,
|
|
392
|
+
result: 123,
|
|
393
|
+
});
|
|
394
|
+
pending.execution = e1;
|
|
395
|
+
plugin.resume(pending);
|
|
396
|
+
|
|
397
|
+
await sleep(500);
|
|
398
|
+
|
|
399
|
+
const [e2] = await workflow.getExecutions();
|
|
400
|
+
expect(e2.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
401
|
+
const jobs = await e2.getJobs({ order: [['id', 'ASC']] });
|
|
402
|
+
console.log(jobs);
|
|
403
|
+
expect(jobs.length).toBe(4);
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
describe('nested', () => {
|
|
408
|
+
it('nested 2 levels', async () => {
|
|
409
|
+
const n1 = await workflow.createNode({
|
|
410
|
+
type: 'parallel',
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
const n2 = await workflow.createNode({
|
|
414
|
+
type: 'parallel',
|
|
415
|
+
upstreamId: n1.id,
|
|
416
|
+
branchIndex: 0,
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
const n3 = await workflow.createNode({
|
|
420
|
+
type: 'echo',
|
|
421
|
+
upstreamId: n1.id,
|
|
422
|
+
branchIndex: 1,
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
const n4 = await workflow.createNode({
|
|
426
|
+
type: 'echo',
|
|
427
|
+
upstreamId: n2.id,
|
|
428
|
+
branchIndex: 0,
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
const n5 = await workflow.createNode({
|
|
432
|
+
type: 'echo',
|
|
433
|
+
upstreamId: n1.id,
|
|
434
|
+
});
|
|
435
|
+
await n1.setDownstream(n5);
|
|
436
|
+
|
|
437
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
438
|
+
|
|
439
|
+
await sleep(500);
|
|
440
|
+
|
|
441
|
+
const [execution] = await workflow.getExecutions();
|
|
442
|
+
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
|
|
443
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
444
|
+
expect(jobs.length).toBe(5);
|
|
445
|
+
});
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
describe('mixed', () => {
|
|
449
|
+
it('condition branches contains parallel', async () => {
|
|
450
|
+
const n1 = await workflow.createNode({
|
|
451
|
+
type: 'condition',
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
const n2 = await workflow.createNode({
|
|
455
|
+
type: 'parallel',
|
|
456
|
+
branchIndex: BRANCH_INDEX.ON_TRUE,
|
|
457
|
+
upstreamId: n1.id,
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
const n3 = await workflow.createNode({
|
|
461
|
+
type: 'prompt',
|
|
462
|
+
upstreamId: n2.id,
|
|
463
|
+
branchIndex: 0,
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
const n4 = await workflow.createNode({
|
|
467
|
+
type: 'echo',
|
|
468
|
+
upstreamId: n2.id,
|
|
469
|
+
branchIndex: 1,
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
const n5 = await workflow.createNode({
|
|
473
|
+
type: 'echo',
|
|
474
|
+
upstreamId: n1.id,
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
await n1.setDownstream(n5);
|
|
478
|
+
|
|
479
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
480
|
+
|
|
481
|
+
await sleep(500);
|
|
482
|
+
|
|
483
|
+
const [execution] = await workflow.getExecutions();
|
|
484
|
+
expect(execution.status).toEqual(EXECUTION_STATUS.STARTED);
|
|
485
|
+
|
|
486
|
+
const pendingJobs = await execution.getJobs();
|
|
487
|
+
expect(pendingJobs.length).toBe(4);
|
|
488
|
+
|
|
489
|
+
const pending = pendingJobs.find((item) => item.nodeId === n3.id);
|
|
490
|
+
pending.set({
|
|
491
|
+
status: JOB_STATUS.RESOLVED,
|
|
492
|
+
result: 123,
|
|
493
|
+
});
|
|
494
|
+
pending.execution = execution;
|
|
495
|
+
await plugin.resume(pending);
|
|
496
|
+
|
|
497
|
+
await sleep(500);
|
|
498
|
+
|
|
499
|
+
expect(execution.status).toEqual(EXECUTION_STATUS.RESOLVED);
|
|
500
|
+
const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
|
|
501
|
+
expect(jobs.length).toEqual(5);
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
it('parallel branches contains condition', async () => {
|
|
505
|
+
const n1 = await workflow.createNode({
|
|
506
|
+
type: 'parallel',
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
const n2 = await workflow.createNode({
|
|
510
|
+
type: 'prompt',
|
|
511
|
+
upstreamId: n1.id,
|
|
512
|
+
branchIndex: 0,
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
const n3 = await workflow.createNode({
|
|
516
|
+
type: 'condition',
|
|
517
|
+
upstreamId: n1.id,
|
|
518
|
+
branchIndex: 1,
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
const n4 = await workflow.createNode({
|
|
522
|
+
type: 'echo',
|
|
523
|
+
upstreamId: n3.id,
|
|
524
|
+
branchIndex: BRANCH_INDEX.ON_TRUE,
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
const n5 = await workflow.createNode({
|
|
528
|
+
type: 'echo',
|
|
529
|
+
upstreamId: n1.id,
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
await n1.setDownstream(n5);
|
|
533
|
+
|
|
534
|
+
const post = await PostRepo.create({ values: { title: 't1' } });
|
|
535
|
+
|
|
536
|
+
await sleep(500);
|
|
537
|
+
|
|
538
|
+
const [e1] = await workflow.getExecutions();
|
|
539
|
+
expect(e1.status).toEqual(EXECUTION_STATUS.STARTED);
|
|
540
|
+
|
|
541
|
+
const pendingJobs = await e1.getJobs();
|
|
542
|
+
expect(pendingJobs.length).toBe(4);
|
|
543
|
+
|
|
544
|
+
const pending = pendingJobs.find((item) => item.nodeId === n2.id);
|
|
545
|
+
pending.set({
|
|
546
|
+
status: JOB_STATUS.RESOLVED,
|
|
547
|
+
result: 123,
|
|
548
|
+
});
|
|
549
|
+
pending.execution = e1;
|
|
550
|
+
await plugin.resume(pending);
|
|
551
|
+
|
|
552
|
+
await sleep(500);
|
|
553
|
+
|
|
554
|
+
const [e2] = await workflow.getExecutions();
|
|
555
|
+
expect(e2.status).toEqual(EXECUTION_STATUS.RESOLVED);
|
|
556
|
+
const jobs = await e2.getJobs({ order: [['id', 'ASC']] });
|
|
557
|
+
expect(jobs.length).toEqual(5);
|
|
558
|
+
});
|
|
559
|
+
});
|
|
560
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './Plugin';
|