bpmn-elements 8.2.0 → 8.2.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/CHANGELOG.md +4 -0
- package/dist/index.js +0 -49
- package/dist/src/Api.js +4 -19
- package/dist/src/Context.js +0 -35
- package/dist/src/Environment.js +18 -44
- package/dist/src/EventBroker.js +8 -27
- package/dist/src/Expressions.js +0 -13
- package/dist/src/ExtensionsMapper.js +0 -12
- package/dist/src/MessageFormatter.js +0 -33
- package/dist/src/Scripts.js +2 -9
- package/dist/src/Timers.js +0 -9
- package/dist/src/activity/Activity.js +39 -243
- package/dist/src/activity/ActivityExecution.js +8 -76
- package/dist/src/activity/Dummy.js +2 -3
- package/dist/src/activity/Escalation.js +4 -4
- package/dist/src/activity/ExecutionScope.js +0 -4
- package/dist/src/activity/Message.js +4 -4
- package/dist/src/activity/Signal.js +4 -4
- package/dist/src/definition/Definition.js +12 -133
- package/dist/src/definition/DefinitionExecution.js +10 -160
- package/dist/src/error/BpmnError.js +2 -3
- package/dist/src/error/Errors.js +0 -16
- package/dist/src/eventDefinitions/CancelEventDefinition.js +2 -35
- package/dist/src/eventDefinitions/CompensateEventDefinition.js +3 -34
- package/dist/src/eventDefinitions/ConditionalEventDefinition.js +3 -42
- package/dist/src/eventDefinitions/ErrorEventDefinition.js +11 -41
- package/dist/src/eventDefinitions/EscalationEventDefinition.js +7 -37
- package/dist/src/eventDefinitions/EventDefinitionExecution.js +0 -30
- package/dist/src/eventDefinitions/LinkEventDefinition.js +11 -37
- package/dist/src/eventDefinitions/MessageEventDefinition.js +11 -44
- package/dist/src/eventDefinitions/SignalEventDefinition.js +9 -46
- package/dist/src/eventDefinitions/TerminateEventDefinition.js +0 -3
- package/dist/src/eventDefinitions/TimerEventDefinition.js +8 -52
- package/dist/src/events/BoundaryEvent.js +4 -44
- package/dist/src/events/EndEvent.js +2 -11
- package/dist/src/events/IntermediateCatchEvent.js +0 -13
- package/dist/src/events/IntermediateThrowEvent.js +2 -11
- package/dist/src/events/StartEvent.js +5 -25
- package/dist/src/flows/Association.js +4 -27
- package/dist/src/flows/MessageFlow.js +6 -18
- package/dist/src/flows/SequenceFlow.js +4 -39
- package/dist/src/gateways/EventBasedGateway.js +0 -21
- package/dist/src/gateways/ExclusiveGateway.js +0 -6
- package/dist/src/gateways/InclusiveGateway.js +0 -6
- package/dist/src/gateways/ParallelGateway.js +2 -7
- package/dist/src/getPropertyValue.js +0 -30
- package/dist/src/io/BpmnIO.js +2 -7
- package/dist/src/io/EnvironmentDataObject.js +0 -8
- package/dist/src/io/EnvironmentDataStore.js +0 -8
- package/dist/src/io/EnvironmentDataStoreReference.js +0 -8
- package/dist/src/io/InputOutputSpecification.js +12 -37
- package/dist/src/io/Properties.js +6 -39
- package/dist/src/messageHelper.js +10 -23
- package/dist/src/process/Process.js +10 -112
- package/dist/src/process/ProcessExecution.js +14 -170
- package/dist/src/shared.js +0 -7
- package/dist/src/tasks/CallActivity.js +2 -23
- package/dist/src/tasks/LoopCharacteristics.js +16 -67
- package/dist/src/tasks/ReceiveTask.js +8 -48
- package/dist/src/tasks/ScriptTask.js +1 -15
- package/dist/src/tasks/ServiceImplementation.js +0 -4
- package/dist/src/tasks/ServiceTask.js +0 -20
- package/dist/src/tasks/SignalTask.js +2 -21
- package/dist/src/tasks/StandardLoopCharacteristics.js +4 -5
- package/dist/src/tasks/SubProcess.js +4 -52
- package/dist/src/tasks/Task.js +0 -8
- package/dist/src/tasks/Transaction.js +0 -3
- package/package.json +7 -7
- package/src/Context.js +0 -1
- package/src/activity/Activity.js +1 -1
- package/src/gateways/EventBasedGateway.js +0 -1
- package/src/io/InputOutputSpecification.js +0 -1
- package/src/process/ProcessExecution.js +2 -1
- package/src/tasks/StandardLoopCharacteristics.js +0 -1
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _Api = require("../Api");
|
|
9
|
-
|
|
10
8
|
var _messageHelper = require("../messageHelper");
|
|
11
|
-
|
|
12
9
|
var _shared = require("../shared");
|
|
13
|
-
|
|
14
10
|
var _default = ProcessExecution;
|
|
15
11
|
exports.default = _default;
|
|
16
12
|
const kActivated = Symbol.for('activated');
|
|
@@ -22,7 +18,6 @@ const kMessageHandlers = Symbol.for('messageHandlers');
|
|
|
22
18
|
const kParent = Symbol.for('parent');
|
|
23
19
|
const kStatus = Symbol.for('status');
|
|
24
20
|
const kStopped = Symbol.for('stopped');
|
|
25
|
-
|
|
26
21
|
function ProcessExecution(parentActivity, context) {
|
|
27
22
|
const {
|
|
28
23
|
id,
|
|
@@ -65,45 +60,35 @@ function ProcessExecution(parentActivity, context) {
|
|
|
65
60
|
onMessageFlowEvent: this._onMessageFlowEvent.bind(this)
|
|
66
61
|
};
|
|
67
62
|
}
|
|
68
|
-
|
|
69
63
|
const proto = ProcessExecution.prototype;
|
|
70
64
|
Object.defineProperty(proto, 'stopped', {
|
|
71
65
|
enumerable: true,
|
|
72
|
-
|
|
73
66
|
get() {
|
|
74
67
|
return this[kStopped];
|
|
75
68
|
}
|
|
76
|
-
|
|
77
69
|
});
|
|
78
70
|
Object.defineProperty(proto, 'completed', {
|
|
79
71
|
enumerable: true,
|
|
80
|
-
|
|
81
72
|
get() {
|
|
82
73
|
return this[kCompleted];
|
|
83
74
|
}
|
|
84
|
-
|
|
85
75
|
});
|
|
86
76
|
Object.defineProperty(proto, 'status', {
|
|
87
77
|
enumerable: true,
|
|
88
|
-
|
|
89
78
|
get() {
|
|
90
79
|
return this[kStatus];
|
|
91
80
|
}
|
|
92
|
-
|
|
93
81
|
});
|
|
94
82
|
Object.defineProperty(proto, 'postponedCount', {
|
|
95
83
|
get() {
|
|
96
84
|
return this[kElements].postponed.length;
|
|
97
85
|
}
|
|
98
|
-
|
|
99
86
|
});
|
|
100
87
|
Object.defineProperty(proto, 'isRunning', {
|
|
101
88
|
get() {
|
|
102
89
|
return this[kActivated];
|
|
103
90
|
}
|
|
104
|
-
|
|
105
91
|
});
|
|
106
|
-
|
|
107
92
|
proto.execute = function execute(executeMessage) {
|
|
108
93
|
if (!executeMessage) throw new Error('Process execution requires message');
|
|
109
94
|
if (!executeMessage.content || !executeMessage.content.executionId) throw new Error('Process execution requires execution id');
|
|
@@ -118,37 +103,26 @@ proto.execute = function execute(executeMessage) {
|
|
|
118
103
|
durable: true,
|
|
119
104
|
autoDelete: false
|
|
120
105
|
});
|
|
121
|
-
|
|
122
106
|
if (executeMessage.fields.redelivered) {
|
|
123
107
|
return this.resume();
|
|
124
108
|
}
|
|
125
|
-
|
|
126
109
|
this._debug(`execute ${this.isSubProcess ? 'sub process' : 'process'}`);
|
|
127
|
-
|
|
128
110
|
this._activate();
|
|
129
|
-
|
|
130
111
|
this._start();
|
|
131
|
-
|
|
132
112
|
return true;
|
|
133
113
|
};
|
|
134
|
-
|
|
135
114
|
proto.resume = function resume() {
|
|
136
115
|
this._debug(`resume process execution at ${this.status}`);
|
|
137
|
-
|
|
138
116
|
if (this[kCompleted]) return this._complete('completed');
|
|
139
|
-
|
|
140
117
|
this._activate();
|
|
141
|
-
|
|
142
118
|
const {
|
|
143
119
|
startActivities,
|
|
144
120
|
detachedActivities,
|
|
145
121
|
postponed
|
|
146
122
|
} = this[kElements];
|
|
147
|
-
|
|
148
123
|
if (startActivities.length > 1) {
|
|
149
124
|
for (const a of startActivities) a.shake();
|
|
150
125
|
}
|
|
151
|
-
|
|
152
126
|
postponed.splice(0);
|
|
153
127
|
detachedActivities.splice(0);
|
|
154
128
|
this[kActivityQ].consume(this[kMessageHandlers].onChildMessage, {
|
|
@@ -156,18 +130,15 @@ proto.resume = function resume() {
|
|
|
156
130
|
consumerTag: `_process-activity-${this.executionId}`
|
|
157
131
|
});
|
|
158
132
|
if (this[kCompleted]) return;
|
|
159
|
-
|
|
160
133
|
switch (this.status) {
|
|
161
134
|
case 'init':
|
|
162
135
|
return this._start();
|
|
163
|
-
|
|
164
136
|
case 'executing':
|
|
165
137
|
{
|
|
166
138
|
if (!postponed.length) return this._complete('completed');
|
|
167
139
|
break;
|
|
168
140
|
}
|
|
169
141
|
}
|
|
170
|
-
|
|
171
142
|
for (const {
|
|
172
143
|
content
|
|
173
144
|
} of postponed.slice()) {
|
|
@@ -177,43 +148,34 @@ proto.resume = function resume() {
|
|
|
177
148
|
activity.resume();
|
|
178
149
|
}
|
|
179
150
|
};
|
|
180
|
-
|
|
181
151
|
proto.recover = function recover(state) {
|
|
182
152
|
if (!state) return this;
|
|
183
153
|
this.executionId = state.executionId;
|
|
184
154
|
this[kStopped] = state.stopped;
|
|
185
155
|
this[kCompleted] = state.completed;
|
|
186
156
|
this[kStatus] = state.status;
|
|
187
|
-
|
|
188
157
|
this._debug(`recover process execution at ${this.status}`);
|
|
189
|
-
|
|
190
158
|
if (state.messageFlows) {
|
|
191
159
|
for (const flowState of state.messageFlows) {
|
|
192
160
|
const flow = this._getMessageFlowById(flowState.id);
|
|
193
|
-
|
|
194
161
|
if (!flow) continue;
|
|
195
162
|
flow.recover(flowState);
|
|
196
163
|
}
|
|
197
164
|
}
|
|
198
|
-
|
|
199
165
|
if (state.associations) {
|
|
200
166
|
for (const associationState of state.associations) {
|
|
201
167
|
const association = this._getAssociationById(associationState.id);
|
|
202
|
-
|
|
203
168
|
if (!association) continue;
|
|
204
169
|
association.recover(associationState);
|
|
205
170
|
}
|
|
206
171
|
}
|
|
207
|
-
|
|
208
172
|
if (state.flows) {
|
|
209
173
|
for (const flowState of state.flows) {
|
|
210
174
|
const flow = this._getFlowById(flowState.id);
|
|
211
|
-
|
|
212
175
|
if (!flow) continue;
|
|
213
176
|
flow.recover(flowState);
|
|
214
177
|
}
|
|
215
178
|
}
|
|
216
|
-
|
|
217
179
|
if (state.children) {
|
|
218
180
|
for (const childState of state.children) {
|
|
219
181
|
const child = this.getActivityById(childState.id);
|
|
@@ -221,32 +183,25 @@ proto.recover = function recover(state) {
|
|
|
221
183
|
child.recover(childState);
|
|
222
184
|
}
|
|
223
185
|
}
|
|
224
|
-
|
|
225
186
|
return this;
|
|
226
187
|
};
|
|
227
|
-
|
|
228
188
|
proto.shake = function shake(fromId) {
|
|
229
189
|
let executing = true;
|
|
230
190
|
const id = this.id;
|
|
231
|
-
|
|
232
191
|
if (!this.isRunning) {
|
|
233
192
|
executing = false;
|
|
234
193
|
this.executionId = (0, _shared.getUniqueId)(id);
|
|
235
|
-
|
|
236
194
|
this._activate();
|
|
237
195
|
}
|
|
238
|
-
|
|
239
196
|
const toShake = fromId ? [this.getActivityById(fromId)].filter(Boolean) : this[kElements].startActivities;
|
|
240
197
|
const result = {};
|
|
241
198
|
this.broker.subscribeTmp('event', '*.shake.*', (routingKey, {
|
|
242
199
|
content
|
|
243
200
|
}) => {
|
|
244
201
|
let isLooped = false;
|
|
245
|
-
|
|
246
202
|
switch (routingKey) {
|
|
247
203
|
case 'flow.shake.loop':
|
|
248
204
|
isLooped = true;
|
|
249
|
-
|
|
250
205
|
case 'activity.shake.end':
|
|
251
206
|
{
|
|
252
207
|
const {
|
|
@@ -255,7 +210,8 @@ proto.shake = function shake(fromId) {
|
|
|
255
210
|
} = content;
|
|
256
211
|
if (shakeParent.id !== id) return;
|
|
257
212
|
result[shakeId] = result[shakeId] || [];
|
|
258
|
-
result[shakeId].push({
|
|
213
|
+
result[shakeId].push({
|
|
214
|
+
...content,
|
|
259
215
|
isLooped
|
|
260
216
|
});
|
|
261
217
|
break;
|
|
@@ -265,31 +221,24 @@ proto.shake = function shake(fromId) {
|
|
|
265
221
|
noAck: true,
|
|
266
222
|
consumerTag: `_shaker-${this.executionId}`
|
|
267
223
|
});
|
|
268
|
-
|
|
269
224
|
for (const a of toShake) a.shake();
|
|
270
|
-
|
|
271
225
|
if (!executing) this._deactivate();
|
|
272
226
|
this.broker.cancel(`_shaker-${this.executionId}`);
|
|
273
227
|
return result;
|
|
274
228
|
};
|
|
275
|
-
|
|
276
229
|
proto.stop = function stop() {
|
|
277
230
|
this.getApi().stop();
|
|
278
231
|
};
|
|
279
|
-
|
|
280
232
|
proto.getPostponed = function getPostponed(filterFn) {
|
|
281
233
|
return this[kElements].postponed.slice().reduce((result, msg) => {
|
|
282
234
|
const api = this._getChildApi(msg);
|
|
283
|
-
|
|
284
235
|
if (api) {
|
|
285
236
|
if (filterFn && !filterFn(api)) return result;
|
|
286
237
|
result.push(api);
|
|
287
238
|
}
|
|
288
|
-
|
|
289
239
|
return result;
|
|
290
240
|
}, []);
|
|
291
241
|
};
|
|
292
|
-
|
|
293
242
|
proto.discard = function discard() {
|
|
294
243
|
this[kStatus] = 'discard';
|
|
295
244
|
return this[kActivityQ].queueMessage({
|
|
@@ -302,7 +251,6 @@ proto.discard = function discard() {
|
|
|
302
251
|
type: 'discard'
|
|
303
252
|
});
|
|
304
253
|
};
|
|
305
|
-
|
|
306
254
|
proto.getState = function getState() {
|
|
307
255
|
const {
|
|
308
256
|
children,
|
|
@@ -331,50 +279,40 @@ proto.getState = function getState() {
|
|
|
331
279
|
})
|
|
332
280
|
};
|
|
333
281
|
};
|
|
334
|
-
|
|
335
282
|
proto.getActivities = function getActivities() {
|
|
336
283
|
return this[kElements].children.slice();
|
|
337
284
|
};
|
|
338
|
-
|
|
339
285
|
proto.getActivityById = function getActivityById(activityId) {
|
|
340
286
|
return this[kElements].children.find(child => child.id === activityId);
|
|
341
287
|
};
|
|
342
|
-
|
|
343
288
|
proto.getSequenceFlows = function getSequenceFlows() {
|
|
344
289
|
return this[kElements].flows.slice();
|
|
345
290
|
};
|
|
346
|
-
|
|
347
291
|
proto.getApi = function getApi(message) {
|
|
348
292
|
if (!message) return (0, _Api.ProcessApi)(this.broker, this[kExecuteMessage]);
|
|
349
293
|
const content = message.content;
|
|
350
|
-
|
|
351
294
|
if (content.executionId !== this.executionId) {
|
|
352
295
|
return this._getChildApi(message);
|
|
353
296
|
}
|
|
354
|
-
|
|
355
297
|
const api = (0, _Api.ProcessApi)(this.broker, message);
|
|
356
298
|
const postponed = this[kElements].postponed;
|
|
357
299
|
const self = this;
|
|
358
|
-
|
|
359
300
|
api.getExecuting = function getExecuting() {
|
|
360
301
|
return postponed.reduce((result, msg) => {
|
|
361
302
|
const childApi = self._getChildApi(msg);
|
|
362
|
-
|
|
363
303
|
if (childApi) result.push(childApi);
|
|
364
304
|
return result;
|
|
365
305
|
}, []);
|
|
366
306
|
};
|
|
367
|
-
|
|
368
307
|
return api;
|
|
369
308
|
};
|
|
370
|
-
|
|
371
309
|
proto._start = function start() {
|
|
372
310
|
if (this[kElements].children.length === 0) {
|
|
373
311
|
return this._complete('completed');
|
|
374
312
|
}
|
|
375
|
-
|
|
376
313
|
this[kStatus] = 'start';
|
|
377
|
-
const executeContent = {
|
|
314
|
+
const executeContent = {
|
|
315
|
+
...this[kExecuteMessage].content,
|
|
378
316
|
state: this.status
|
|
379
317
|
};
|
|
380
318
|
this.broker.publish(this._exchangeName, 'execute.start', (0, _messageHelper.cloneContent)(executeContent));
|
|
@@ -383,15 +321,11 @@ proto._start = function start() {
|
|
|
383
321
|
postponed,
|
|
384
322
|
detachedActivities
|
|
385
323
|
} = this[kElements];
|
|
386
|
-
|
|
387
324
|
if (startActivities.length > 1) {
|
|
388
325
|
for (const a of startActivities) a.shake();
|
|
389
326
|
}
|
|
390
|
-
|
|
391
327
|
for (const a of startActivities) a.init();
|
|
392
|
-
|
|
393
328
|
for (const a of startActivities) a.run();
|
|
394
|
-
|
|
395
329
|
postponed.splice(0);
|
|
396
330
|
detachedActivities.splice(0);
|
|
397
331
|
this[kActivityQ].assertConsumer(this[kMessageHandlers].onChildMessage, {
|
|
@@ -399,7 +333,6 @@ proto._start = function start() {
|
|
|
399
333
|
consumerTag: `_process-activity-${this.executionId}`
|
|
400
334
|
});
|
|
401
335
|
};
|
|
402
|
-
|
|
403
336
|
proto._activate = function activate() {
|
|
404
337
|
const {
|
|
405
338
|
onApiMessage,
|
|
@@ -419,7 +352,6 @@ proto._activate = function activate() {
|
|
|
419
352
|
triggeredByEvent,
|
|
420
353
|
children
|
|
421
354
|
} = this[kElements];
|
|
422
|
-
|
|
423
355
|
for (const flow of outboundMessageFlows) {
|
|
424
356
|
flow.activate();
|
|
425
357
|
flow.broker.subscribeTmp('event', '#', onMessageFlowEvent, {
|
|
@@ -428,7 +360,6 @@ proto._activate = function activate() {
|
|
|
428
360
|
priority: 200
|
|
429
361
|
});
|
|
430
362
|
}
|
|
431
|
-
|
|
432
363
|
for (const flow of flows) {
|
|
433
364
|
flow.broker.subscribeTmp('event', '#', onActivityEvent, {
|
|
434
365
|
consumerTag: '_process-flow-controller',
|
|
@@ -436,7 +367,6 @@ proto._activate = function activate() {
|
|
|
436
367
|
priority: 200
|
|
437
368
|
});
|
|
438
369
|
}
|
|
439
|
-
|
|
440
370
|
for (const association of associations) {
|
|
441
371
|
association.broker.subscribeTmp('event', '#', onActivityEvent, {
|
|
442
372
|
consumerTag: '_process-association-controller',
|
|
@@ -444,10 +374,8 @@ proto._activate = function activate() {
|
|
|
444
374
|
priority: 200
|
|
445
375
|
});
|
|
446
376
|
}
|
|
447
|
-
|
|
448
377
|
startActivities.splice(0);
|
|
449
378
|
triggeredByEvent.splice(0);
|
|
450
|
-
|
|
451
379
|
for (const activity of children) {
|
|
452
380
|
if (activity.placeholder) continue;
|
|
453
381
|
activity.activate(this);
|
|
@@ -459,10 +387,8 @@ proto._activate = function activate() {
|
|
|
459
387
|
if (activity.isStart) startActivities.push(activity);
|
|
460
388
|
if (activity.triggeredByEvent) triggeredByEvent.push(activity);
|
|
461
389
|
}
|
|
462
|
-
|
|
463
390
|
this[kActivated] = true;
|
|
464
391
|
};
|
|
465
|
-
|
|
466
392
|
proto._deactivate = function deactivate() {
|
|
467
393
|
const broker = this.broker;
|
|
468
394
|
const executionId = this.executionId;
|
|
@@ -474,40 +400,32 @@ proto._deactivate = function deactivate() {
|
|
|
474
400
|
associations,
|
|
475
401
|
outboundMessageFlows
|
|
476
402
|
} = this[kElements];
|
|
477
|
-
|
|
478
403
|
for (const activity of children) {
|
|
479
404
|
if (activity.placeholder) continue;
|
|
480
405
|
activity.broker.cancel('_process-activity-consumer');
|
|
481
406
|
activity.deactivate();
|
|
482
407
|
}
|
|
483
|
-
|
|
484
408
|
for (const flow of flows) {
|
|
485
409
|
flow.broker.cancel('_process-flow-controller');
|
|
486
410
|
}
|
|
487
|
-
|
|
488
411
|
for (const association of associations) {
|
|
489
412
|
association.broker.cancel('_process-association-controller');
|
|
490
413
|
}
|
|
491
|
-
|
|
492
414
|
for (const flow of outboundMessageFlows) {
|
|
493
415
|
flow.deactivate();
|
|
494
416
|
flow.broker.cancel('_process-message-consumer');
|
|
495
417
|
}
|
|
496
|
-
|
|
497
418
|
this[kActivated] = false;
|
|
498
419
|
};
|
|
499
|
-
|
|
500
420
|
proto._onDelegateEvent = function onDelegateEvent(message) {
|
|
501
421
|
const eventType = message.properties.type;
|
|
502
422
|
let delegate = true;
|
|
503
423
|
const content = message.content;
|
|
504
|
-
|
|
505
424
|
if (content.message && content.message.id) {
|
|
506
425
|
this._debug(`delegate ${eventType} event with id <${content.message.id}>`);
|
|
507
426
|
} else {
|
|
508
427
|
this._debug(`delegate ${eventType} anonymous event`);
|
|
509
428
|
}
|
|
510
|
-
|
|
511
429
|
for (const activity of this[kElements].triggeredByEvent) {
|
|
512
430
|
if (activity.getStartActivities({
|
|
513
431
|
referenceId: content.message && content.message.id,
|
|
@@ -517,17 +435,14 @@ proto._onDelegateEvent = function onDelegateEvent(message) {
|
|
|
517
435
|
activity.run(content.message);
|
|
518
436
|
}
|
|
519
437
|
}
|
|
520
|
-
|
|
521
438
|
this.getApi().sendApiMessage(eventType, content, {
|
|
522
439
|
delegate: true
|
|
523
440
|
});
|
|
524
441
|
return delegate;
|
|
525
442
|
};
|
|
526
|
-
|
|
527
443
|
proto._onMessageFlowEvent = function onMessageFlowEvent(routingKey, message) {
|
|
528
444
|
this.broker.publish('message', routingKey, (0, _messageHelper.cloneContent)(message.content), message.properties);
|
|
529
445
|
};
|
|
530
|
-
|
|
531
446
|
proto._onActivityEvent = function onActivityEvent(routingKey, message) {
|
|
532
447
|
if (message.fields.redelivered && message.properties.persistent === false) return;
|
|
533
448
|
const content = message.content;
|
|
@@ -535,7 +450,6 @@ proto._onActivityEvent = function onActivityEvent(routingKey, message) {
|
|
|
535
450
|
let delegate = message.properties.delegate;
|
|
536
451
|
const shaking = message.properties.type === 'shake';
|
|
537
452
|
const isDirectChild = content.parent.id === this.id;
|
|
538
|
-
|
|
539
453
|
if (isDirectChild) {
|
|
540
454
|
parent.executionId = this.executionId;
|
|
541
455
|
} else {
|
|
@@ -545,16 +459,15 @@ proto._onActivityEvent = function onActivityEvent(routingKey, message) {
|
|
|
545
459
|
executionId: this.executionId
|
|
546
460
|
});
|
|
547
461
|
}
|
|
548
|
-
|
|
549
462
|
if (delegate) delegate = this._onDelegateEvent(message);
|
|
550
|
-
this.broker.publish('event', routingKey, content, {
|
|
463
|
+
this.broker.publish('event', routingKey, content, {
|
|
464
|
+
...message.properties,
|
|
551
465
|
delegate,
|
|
552
466
|
mandatory: false
|
|
553
467
|
});
|
|
554
468
|
if (shaking) return this._onShookEnd(message);
|
|
555
469
|
if (!isDirectChild) return;
|
|
556
470
|
if (content.isAssociation) return;
|
|
557
|
-
|
|
558
471
|
switch (routingKey) {
|
|
559
472
|
case 'process.terminate':
|
|
560
473
|
return this[kActivityQ].queueMessage({
|
|
@@ -563,92 +476,76 @@ proto._onActivityEvent = function onActivityEvent(routingKey, message) {
|
|
|
563
476
|
type: 'terminate',
|
|
564
477
|
persistent: true
|
|
565
478
|
});
|
|
566
|
-
|
|
567
479
|
case 'activity.stop':
|
|
568
480
|
return;
|
|
569
481
|
}
|
|
570
|
-
|
|
571
482
|
this[kActivityQ].queueMessage(message.fields, (0, _messageHelper.cloneContent)(content), {
|
|
572
483
|
persistent: true,
|
|
573
484
|
...message.properties
|
|
574
485
|
});
|
|
575
486
|
};
|
|
576
|
-
|
|
577
487
|
proto._onChildMessage = function onChildMessage(routingKey, message) {
|
|
578
488
|
if (message.fields.redelivered && message.properties.persistent === false) return message.ack();
|
|
579
489
|
const content = message.content;
|
|
580
|
-
|
|
581
490
|
switch (routingKey) {
|
|
582
491
|
case 'execution.stop':
|
|
583
492
|
message.ack();
|
|
584
493
|
return this._stopExecution(message);
|
|
585
|
-
|
|
586
494
|
case 'execution.terminate':
|
|
587
495
|
message.ack();
|
|
588
496
|
return this._terminate(message);
|
|
589
|
-
|
|
590
497
|
case 'execution.discard':
|
|
591
498
|
message.ack();
|
|
592
499
|
return this._onDiscard(message);
|
|
593
|
-
|
|
594
500
|
case 'activity.compensation.end':
|
|
595
501
|
case 'flow.looped':
|
|
596
502
|
case 'activity.leave':
|
|
597
503
|
return this._onChildCompleted(message);
|
|
598
504
|
}
|
|
599
|
-
|
|
600
505
|
this._stateChangeMessage(message, true);
|
|
601
|
-
|
|
602
506
|
switch (routingKey) {
|
|
603
507
|
case 'activity.detach':
|
|
604
508
|
{
|
|
605
509
|
this[kElements].detachedActivities.push((0, _messageHelper.cloneMessage)(message));
|
|
606
510
|
break;
|
|
607
511
|
}
|
|
608
|
-
|
|
609
512
|
case 'activity.discard':
|
|
610
513
|
case 'activity.compensation.start':
|
|
611
514
|
case 'activity.enter':
|
|
612
515
|
{
|
|
613
516
|
this[kStatus] = 'executing';
|
|
614
517
|
if (!content.inbound) break;
|
|
615
|
-
|
|
616
518
|
for (const inbound of content.inbound) {
|
|
617
519
|
if (!inbound.isSequenceFlow) continue;
|
|
618
|
-
|
|
619
520
|
const inboundMessage = this._popPostponed(inbound);
|
|
620
|
-
|
|
621
521
|
if (inboundMessage) inboundMessage.ack();
|
|
622
522
|
}
|
|
623
|
-
|
|
624
523
|
break;
|
|
625
524
|
}
|
|
626
|
-
|
|
627
525
|
case 'activity.error':
|
|
628
526
|
{
|
|
629
527
|
const eventCaughtBy = this[kElements].postponed.find(msg => {
|
|
630
528
|
if (msg.fields.routingKey !== 'activity.catch') return;
|
|
631
529
|
return msg.content.source && msg.content.source.executionId === content.executionId;
|
|
632
530
|
});
|
|
633
|
-
|
|
634
531
|
if (eventCaughtBy) {
|
|
532
|
+
this[kActivityQ].queueMessage({
|
|
533
|
+
routingKey: 'activity.caught'
|
|
534
|
+
}, (0, _messageHelper.cloneContent)(content), message.properties);
|
|
535
|
+
message.ack();
|
|
635
536
|
return this._debug('error was caught');
|
|
636
537
|
}
|
|
637
|
-
|
|
638
538
|
return this._complete('error', {
|
|
639
539
|
error: content.error
|
|
640
540
|
});
|
|
641
541
|
}
|
|
642
542
|
}
|
|
643
543
|
};
|
|
644
|
-
|
|
645
544
|
proto._stateChangeMessage = function stateChangeMessage(message, postponeMessage) {
|
|
646
545
|
const previousMsg = this._popPostponed(message.content);
|
|
647
|
-
|
|
648
546
|
if (previousMsg) previousMsg.ack();
|
|
649
547
|
if (postponeMessage) this[kElements].postponed.push(message);
|
|
650
548
|
};
|
|
651
|
-
|
|
652
549
|
proto._popPostponed = function popPostponed(byContent) {
|
|
653
550
|
const {
|
|
654
551
|
postponed,
|
|
@@ -659,19 +556,15 @@ proto._popPostponed = function popPostponed(byContent) {
|
|
|
659
556
|
return msg.content.executionId === byContent.executionId;
|
|
660
557
|
});
|
|
661
558
|
let postponedMsg;
|
|
662
|
-
|
|
663
559
|
if (postponedIdx > -1) {
|
|
664
560
|
postponedMsg = postponed.splice(postponedIdx, 1)[0];
|
|
665
561
|
}
|
|
666
|
-
|
|
667
562
|
const detachedIdx = detachedActivities.findIndex(msg => msg.content.executionId === byContent.executionId);
|
|
668
563
|
if (detachedIdx > -1) detachedActivities.splice(detachedIdx, 1);
|
|
669
564
|
return postponedMsg;
|
|
670
565
|
};
|
|
671
|
-
|
|
672
566
|
proto._onChildCompleted = function onChildCompleted(message) {
|
|
673
567
|
this._stateChangeMessage(message, false);
|
|
674
|
-
|
|
675
568
|
if (message.fields.redelivered) return message.ack();
|
|
676
569
|
const {
|
|
677
570
|
id,
|
|
@@ -684,29 +577,21 @@ proto._onChildCompleted = function onChildCompleted(message) {
|
|
|
684
577
|
startActivities
|
|
685
578
|
} = this[kElements];
|
|
686
579
|
const postponedCount = postponed.length;
|
|
687
|
-
|
|
688
580
|
if (!postponedCount) {
|
|
689
581
|
this._debug(`left <${id}> (${type}), pending runs ${postponedCount}`);
|
|
690
|
-
|
|
691
582
|
message.ack();
|
|
692
583
|
return this._complete('completed');
|
|
693
584
|
}
|
|
694
|
-
|
|
695
585
|
this._debug(`left <${id}> (${type}), pending runs ${postponedCount}, ${postponed.map(a => a.content.id).join(',')}`);
|
|
696
|
-
|
|
697
586
|
if (postponedCount === detachedActivities.length) {
|
|
698
587
|
for (const api of this.getPostponed()) api.discard();
|
|
699
|
-
|
|
700
588
|
return;
|
|
701
589
|
}
|
|
702
|
-
|
|
703
590
|
if (isEnd && startActivities.length) {
|
|
704
591
|
const startSequences = this[kElements].startSequences;
|
|
705
|
-
|
|
706
592
|
for (const msg of postponed) {
|
|
707
593
|
const postponedId = msg.content.id;
|
|
708
594
|
const startSequence = startSequences[postponedId];
|
|
709
|
-
|
|
710
595
|
if (startSequence) {
|
|
711
596
|
if (startSequence.content.sequence.some(({
|
|
712
597
|
id: sid
|
|
@@ -717,84 +602,63 @@ proto._onChildCompleted = function onChildCompleted(message) {
|
|
|
717
602
|
}
|
|
718
603
|
}
|
|
719
604
|
};
|
|
720
|
-
|
|
721
605
|
proto._stopExecution = function stopExecution(message) {
|
|
722
606
|
const postponedCount = this.postponedCount;
|
|
723
|
-
|
|
724
607
|
this._debug(`stop process execution (stop child executions ${postponedCount})`);
|
|
725
|
-
|
|
726
608
|
if (postponedCount) {
|
|
727
609
|
for (const api of this.getPostponed()) api.stop();
|
|
728
610
|
}
|
|
729
|
-
|
|
730
611
|
this._deactivate();
|
|
731
|
-
|
|
732
612
|
this[kStopped] = true;
|
|
733
|
-
return this.broker.publish(this._exchangeName, `execution.stopped.${this.executionId}`, {
|
|
613
|
+
return this.broker.publish(this._exchangeName, `execution.stopped.${this.executionId}`, {
|
|
614
|
+
...this[kExecuteMessage].content,
|
|
734
615
|
...(message && message.content)
|
|
735
616
|
}, {
|
|
736
617
|
type: 'stopped',
|
|
737
618
|
persistent: false
|
|
738
619
|
});
|
|
739
620
|
};
|
|
740
|
-
|
|
741
621
|
proto._onDiscard = function onDiscard() {
|
|
742
622
|
this._deactivate();
|
|
743
|
-
|
|
744
623
|
const running = this[kElements].postponed.splice(0);
|
|
745
|
-
|
|
746
624
|
this._debug(`discard process execution (discard child executions ${running.length})`);
|
|
747
|
-
|
|
748
625
|
for (const flow of this.getSequenceFlows()) flow.stop();
|
|
749
|
-
|
|
750
626
|
for (const msg of running) this._getChildApi(msg).discard();
|
|
751
|
-
|
|
752
627
|
this[kActivityQ].purge();
|
|
753
628
|
return this._complete('discard');
|
|
754
629
|
};
|
|
755
|
-
|
|
756
630
|
proto._onApiMessage = function onApiMessage(routingKey, message) {
|
|
757
631
|
const executionId = this.executionId;
|
|
758
632
|
const broker = this.broker;
|
|
759
|
-
|
|
760
633
|
if (message.properties.delegate) {
|
|
761
634
|
const correlationId = message.properties.correlationId || (0, _shared.getUniqueId)(executionId);
|
|
762
|
-
|
|
763
635
|
this._debug(`delegate api ${routingKey} message to children, with correlationId <${correlationId}>`);
|
|
764
|
-
|
|
765
636
|
let consumed = false;
|
|
766
637
|
broker.subscribeTmp('event', 'activity.consumed', (_, msg) => {
|
|
767
638
|
if (msg.properties.correlationId === correlationId) {
|
|
768
639
|
consumed = true;
|
|
769
|
-
|
|
770
640
|
this._debug(`delegated api message was consumed by ${msg.content ? msg.content.executionId : 'unknown'}`);
|
|
771
641
|
}
|
|
772
642
|
}, {
|
|
773
643
|
consumerTag: `_ct-delegate-${correlationId}`,
|
|
774
644
|
noAck: true
|
|
775
645
|
});
|
|
776
|
-
|
|
777
646
|
for (const child of this[kElements].children) {
|
|
778
647
|
if (child.placeholder) continue;
|
|
779
648
|
child.broker.publish('api', routingKey, (0, _messageHelper.cloneContent)(message.content), message.properties);
|
|
780
649
|
if (consumed) break;
|
|
781
650
|
}
|
|
782
|
-
|
|
783
651
|
return broker.cancel(`_ct-delegate-${correlationId}`);
|
|
784
652
|
}
|
|
785
|
-
|
|
786
653
|
if (this.id !== message.content.id) {
|
|
787
654
|
const child = this.getActivityById(message.content.id);
|
|
788
655
|
if (!child) return null;
|
|
789
656
|
return child.broker.publish('api', routingKey, message.content, message.properties);
|
|
790
657
|
}
|
|
791
|
-
|
|
792
658
|
if (this.executionId !== message.content.executionId) return;
|
|
793
|
-
|
|
794
659
|
switch (message.properties.type) {
|
|
795
660
|
case 'discard':
|
|
796
661
|
return this.discard(message);
|
|
797
|
-
|
|
798
662
|
case 'stop':
|
|
799
663
|
this[kActivityQ].queueMessage({
|
|
800
664
|
routingKey: 'execution.stop'
|
|
@@ -804,18 +668,16 @@ proto._onApiMessage = function onApiMessage(routingKey, message) {
|
|
|
804
668
|
break;
|
|
805
669
|
}
|
|
806
670
|
};
|
|
807
|
-
|
|
808
671
|
proto._complete = function complete(completionType, content) {
|
|
809
672
|
this._deactivate();
|
|
810
|
-
|
|
811
673
|
this._debug(`process execution ${completionType}`);
|
|
812
|
-
|
|
813
674
|
this[kCompleted] = true;
|
|
814
675
|
if (this.status !== 'terminated') this[kStatus] = completionType;
|
|
815
676
|
const broker = this.broker;
|
|
816
677
|
this[kActivityQ].delete();
|
|
817
678
|
return broker.publish(this._exchangeName, `execution.${completionType}.${this.executionId}`, (0, _messageHelper.cloneContent)(this[kExecuteMessage].content, {
|
|
818
|
-
output: {
|
|
679
|
+
output: {
|
|
680
|
+
...this.environment.output
|
|
819
681
|
},
|
|
820
682
|
...content,
|
|
821
683
|
state: completionType
|
|
@@ -824,16 +686,11 @@ proto._complete = function complete(completionType, content) {
|
|
|
824
686
|
mandatory: completionType === 'error'
|
|
825
687
|
});
|
|
826
688
|
};
|
|
827
|
-
|
|
828
689
|
proto._terminate = function terminate(message) {
|
|
829
690
|
this[kStatus] = 'terminated';
|
|
830
|
-
|
|
831
691
|
this._debug('terminating process execution');
|
|
832
|
-
|
|
833
692
|
const running = this[kElements].postponed.splice(0);
|
|
834
|
-
|
|
835
693
|
for (const flow of this.getSequenceFlows()) flow.stop();
|
|
836
|
-
|
|
837
694
|
for (const msg of running) {
|
|
838
695
|
const {
|
|
839
696
|
id: postponedId,
|
|
@@ -841,54 +698,41 @@ proto._terminate = function terminate(message) {
|
|
|
841
698
|
} = msg.content;
|
|
842
699
|
if (postponedId === message.content.id) continue;
|
|
843
700
|
if (isSequenceFlow) continue;
|
|
844
|
-
|
|
845
701
|
this._getChildApi(msg).stop();
|
|
846
|
-
|
|
847
702
|
msg.ack();
|
|
848
703
|
}
|
|
849
|
-
|
|
850
704
|
this[kActivityQ].purge();
|
|
851
705
|
};
|
|
852
|
-
|
|
853
706
|
proto._getFlowById = function getFlowById(flowId) {
|
|
854
707
|
return this[kElements].flows.find(f => f.id === flowId);
|
|
855
708
|
};
|
|
856
|
-
|
|
857
709
|
proto._getAssociationById = function getAssociationById(associationId) {
|
|
858
710
|
return this[kElements].associations.find(a => a.id === associationId);
|
|
859
711
|
};
|
|
860
|
-
|
|
861
712
|
proto._getMessageFlowById = function getMessageFlowById(flowId) {
|
|
862
713
|
return this[kElements].outboundMessageFlows.find(f => f.id === flowId);
|
|
863
714
|
};
|
|
864
|
-
|
|
865
715
|
proto._getChildById = function getChildById(childId) {
|
|
866
716
|
return this.getActivityById(childId) || this._getFlowById(childId);
|
|
867
717
|
};
|
|
868
|
-
|
|
869
718
|
proto._getChildApi = function getChildApi(message) {
|
|
870
719
|
const content = message.content;
|
|
871
|
-
|
|
872
720
|
let child = this._getChildById(content.id);
|
|
873
|
-
|
|
874
721
|
if (child) return child.getApi(message);
|
|
875
722
|
if (!content.parent) return;
|
|
876
723
|
child = this._getChildById(content.parent.id);
|
|
877
724
|
if (child) return child.getApi(message);
|
|
878
725
|
if (!content.parent.path) return;
|
|
879
|
-
|
|
880
726
|
for (const pp of content.parent.path) {
|
|
881
727
|
child = this._getChildById(pp.id, message);
|
|
882
728
|
if (child) return child.getApi(message);
|
|
883
729
|
}
|
|
884
730
|
};
|
|
885
|
-
|
|
886
731
|
proto._onShookEnd = function onShookEnd(message) {
|
|
887
732
|
const routingKey = message.fields.routingKey;
|
|
888
733
|
if (routingKey !== 'activity.shake.end') return;
|
|
889
734
|
this[kElements].startSequences[message.content.id] = (0, _messageHelper.cloneMessage)(message);
|
|
890
735
|
};
|
|
891
|
-
|
|
892
736
|
proto._debug = function debugMessage(logMessage) {
|
|
893
737
|
this[kParent].logger.debug(`<${this.executionId} (${this.id})> ${logMessage}`);
|
|
894
738
|
};
|