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,17 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = DefinitionExecution;
|
|
7
|
-
|
|
8
7
|
var _getPropertyValue = _interopRequireDefault(require("../getPropertyValue"));
|
|
9
|
-
|
|
10
8
|
var _Api = require("../Api");
|
|
11
|
-
|
|
12
9
|
var _shared = require("../shared");
|
|
13
|
-
|
|
14
10
|
var _messageHelper = require("../messageHelper");
|
|
15
|
-
|
|
16
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
12
|
const kActivated = Symbol.for('activated');
|
|
19
13
|
const kProcessesQ = Symbol.for('processesQ');
|
|
20
14
|
const kCompleted = Symbol.for('completed');
|
|
@@ -24,7 +18,6 @@ const kParent = Symbol.for('definition');
|
|
|
24
18
|
const kProcesses = Symbol.for('processes');
|
|
25
19
|
const kStatus = Symbol.for('status');
|
|
26
20
|
const kStopped = Symbol.for('stopped');
|
|
27
|
-
|
|
28
21
|
function DefinitionExecution(definition, context) {
|
|
29
22
|
const broker = definition.broker;
|
|
30
23
|
this[kParent] = definition;
|
|
@@ -36,14 +29,12 @@ function DefinitionExecution(definition, context) {
|
|
|
36
29
|
const processes = context.getProcesses();
|
|
37
30
|
const ids = [];
|
|
38
31
|
const executable = [];
|
|
39
|
-
|
|
40
32
|
for (const bp of processes) {
|
|
41
33
|
bp.environment.assignVariables(environment.variables);
|
|
42
34
|
bp.environment.assignSettings(environment.settings);
|
|
43
35
|
ids.push(bp.id);
|
|
44
36
|
if (bp.isExecutable) executable.push(bp);
|
|
45
37
|
}
|
|
46
|
-
|
|
47
38
|
this[kProcesses] = {
|
|
48
39
|
processes,
|
|
49
40
|
running: [],
|
|
@@ -71,53 +62,41 @@ function DefinitionExecution(definition, context) {
|
|
|
71
62
|
onProcessMessage: this._onProcessMessage.bind(this)
|
|
72
63
|
};
|
|
73
64
|
}
|
|
74
|
-
|
|
75
65
|
const proto = DefinitionExecution.prototype;
|
|
76
66
|
Object.defineProperty(proto, 'stopped', {
|
|
77
67
|
enumerable: true,
|
|
78
|
-
|
|
79
68
|
get() {
|
|
80
69
|
return this[kStopped];
|
|
81
70
|
}
|
|
82
|
-
|
|
83
71
|
});
|
|
84
72
|
Object.defineProperty(proto, 'completed', {
|
|
85
73
|
enumerable: true,
|
|
86
|
-
|
|
87
74
|
get() {
|
|
88
75
|
return this[kCompleted];
|
|
89
76
|
}
|
|
90
|
-
|
|
91
77
|
});
|
|
92
78
|
Object.defineProperty(proto, 'status', {
|
|
93
79
|
enumerable: true,
|
|
94
|
-
|
|
95
80
|
get() {
|
|
96
81
|
return this[kStatus];
|
|
97
82
|
}
|
|
98
|
-
|
|
99
83
|
});
|
|
100
84
|
Object.defineProperty(proto, 'processes', {
|
|
101
85
|
enumerable: true,
|
|
102
|
-
|
|
103
86
|
get() {
|
|
104
87
|
return this[kProcesses].running;
|
|
105
88
|
}
|
|
106
|
-
|
|
107
89
|
});
|
|
108
90
|
Object.defineProperty(proto, 'postponedCount', {
|
|
109
91
|
get() {
|
|
110
92
|
return this[kProcesses].postponed.length;
|
|
111
93
|
}
|
|
112
|
-
|
|
113
94
|
});
|
|
114
95
|
Object.defineProperty(proto, 'isRunning', {
|
|
115
96
|
get() {
|
|
116
97
|
return this[kActivated];
|
|
117
98
|
}
|
|
118
|
-
|
|
119
99
|
});
|
|
120
|
-
|
|
121
100
|
proto.execute = function execute(executeMessage) {
|
|
122
101
|
if (!executeMessage) throw new Error('Definition execution requires message');
|
|
123
102
|
const content = executeMessage.content;
|
|
@@ -132,129 +111,98 @@ proto.execute = function execute(executeMessage) {
|
|
|
132
111
|
durable: true,
|
|
133
112
|
autoDelete: false
|
|
134
113
|
});
|
|
135
|
-
|
|
136
114
|
if (executeMessage.fields.redelivered) {
|
|
137
115
|
return this.resume();
|
|
138
116
|
}
|
|
139
|
-
|
|
140
117
|
const {
|
|
141
118
|
running,
|
|
142
119
|
executable
|
|
143
120
|
} = this[kProcesses];
|
|
144
|
-
|
|
145
121
|
if (content.processId) {
|
|
146
122
|
const startWithProcess = this.getProcessById(content.processId);
|
|
147
|
-
|
|
148
123
|
if (startWithProcess) {
|
|
149
124
|
executable.splice(0);
|
|
150
125
|
executable.push(startWithProcess);
|
|
151
126
|
}
|
|
152
127
|
}
|
|
153
|
-
|
|
154
128
|
this._debug('execute definition');
|
|
155
|
-
|
|
156
129
|
running.push(...executable);
|
|
157
|
-
|
|
158
130
|
this._activate(executable);
|
|
159
|
-
|
|
160
131
|
this._start();
|
|
161
|
-
|
|
162
132
|
return true;
|
|
163
133
|
};
|
|
164
|
-
|
|
165
134
|
proto.resume = function resume() {
|
|
166
135
|
this._debug(`resume ${this[kStatus]} definition execution`);
|
|
167
|
-
|
|
168
136
|
if (this[kCompleted]) return this._complete('completed');
|
|
169
137
|
const {
|
|
170
138
|
running,
|
|
171
139
|
postponed
|
|
172
140
|
} = this[kProcesses];
|
|
173
|
-
|
|
174
141
|
this._activate(running);
|
|
175
|
-
|
|
176
142
|
postponed.splice(0);
|
|
177
143
|
this[kProcessesQ].consume(this[kMessageHandlers].onProcessMessage, {
|
|
178
144
|
prefetch: 1000,
|
|
179
145
|
consumerTag: `_definition-activity-${this.executionId}`
|
|
180
146
|
});
|
|
181
147
|
if (this[kCompleted]) return;
|
|
182
|
-
|
|
183
148
|
for (const bp of running) bp.resume();
|
|
184
149
|
};
|
|
185
|
-
|
|
186
150
|
proto.recover = function recover(state) {
|
|
187
151
|
if (!state) return this;
|
|
188
152
|
this.executionId = state.executionId;
|
|
189
153
|
this[kStopped] = state.stopped;
|
|
190
154
|
this[kCompleted] = state.completed;
|
|
191
155
|
this[kStatus] = state.status;
|
|
192
|
-
|
|
193
156
|
this._debug(`recover ${this[kStatus]} definition execution`);
|
|
194
|
-
|
|
195
157
|
const running = this[kProcesses].running;
|
|
196
158
|
running.splice(0);
|
|
197
159
|
const ids = [];
|
|
198
|
-
|
|
199
160
|
for (const bpState of state.processes) {
|
|
200
161
|
const bpid = bpState.id;
|
|
201
162
|
let bp;
|
|
202
|
-
|
|
203
163
|
if (ids.indexOf(bpid) > -1) {
|
|
204
164
|
bp = this.context.getNewProcessById(bpid);
|
|
205
165
|
} else {
|
|
206
166
|
bp = this.getProcessById(bpid);
|
|
207
167
|
}
|
|
208
|
-
|
|
209
168
|
if (!bp) return;
|
|
210
169
|
ids.push(bpid);
|
|
211
170
|
bp.recover(bpState);
|
|
212
171
|
running.push(bp);
|
|
213
172
|
}
|
|
214
|
-
|
|
215
173
|
return this;
|
|
216
174
|
};
|
|
217
|
-
|
|
218
175
|
proto.stop = function stop() {
|
|
219
176
|
this.getApi().stop();
|
|
220
177
|
};
|
|
221
|
-
|
|
222
178
|
proto.getProcesses = function getProcesses() {
|
|
223
179
|
const {
|
|
224
180
|
running,
|
|
225
181
|
processes
|
|
226
182
|
} = this[kProcesses];
|
|
227
183
|
const result = running.slice();
|
|
228
|
-
|
|
229
184
|
for (const bp of processes) {
|
|
230
185
|
if (!result.find(runningBp => bp.id === runningBp.id)) result.push(bp);
|
|
231
186
|
}
|
|
232
|
-
|
|
233
187
|
return result;
|
|
234
188
|
};
|
|
235
|
-
|
|
236
189
|
proto.getProcessById = function getProcessById(processId) {
|
|
237
190
|
return this.getProcesses().find(bp => bp.id === processId);
|
|
238
191
|
};
|
|
239
|
-
|
|
240
192
|
proto.getProcessesById = function getProcessesById(processId) {
|
|
241
193
|
return this.getProcesses().filter(bp => bp.id === processId);
|
|
242
194
|
};
|
|
243
|
-
|
|
244
195
|
proto.getProcessByExecutionId = function getProcessByExecutionId(processExecutionId) {
|
|
245
196
|
const running = this[kProcesses].running;
|
|
246
197
|
return running.find(bp => bp.executionId === processExecutionId);
|
|
247
198
|
};
|
|
248
|
-
|
|
249
199
|
proto.getRunningProcesses = function getRunningProcesses() {
|
|
250
200
|
const running = this[kProcesses].running;
|
|
251
201
|
return running.filter(bp => bp.executionId);
|
|
252
202
|
};
|
|
253
|
-
|
|
254
203
|
proto.getExecutableProcesses = function getExecutableProcesses() {
|
|
255
204
|
return this[kProcesses].executable.slice();
|
|
256
205
|
};
|
|
257
|
-
|
|
258
206
|
proto.getState = function getState() {
|
|
259
207
|
return {
|
|
260
208
|
executionId: this.executionId,
|
|
@@ -264,33 +212,26 @@ proto.getState = function getState() {
|
|
|
264
212
|
processes: this[kProcesses].running.map(bp => bp.getState())
|
|
265
213
|
};
|
|
266
214
|
};
|
|
267
|
-
|
|
268
215
|
proto.getApi = function getApi(apiMessage) {
|
|
269
216
|
if (!apiMessage) apiMessage = this[kExecuteMessage] || {
|
|
270
217
|
content: this._createMessage()
|
|
271
218
|
};
|
|
272
219
|
const content = apiMessage.content;
|
|
273
|
-
|
|
274
220
|
if (content.executionId !== this.executionId) {
|
|
275
221
|
return this._getProcessApi(apiMessage);
|
|
276
222
|
}
|
|
277
|
-
|
|
278
223
|
const api = (0, _Api.DefinitionApi)(this.broker, apiMessage);
|
|
279
224
|
const postponed = this[kProcesses].postponed;
|
|
280
225
|
const self = this;
|
|
281
|
-
|
|
282
226
|
api.getExecuting = function getExecuting() {
|
|
283
227
|
return postponed.reduce((result, msg) => {
|
|
284
228
|
const bpApi = self._getProcessApi(msg);
|
|
285
|
-
|
|
286
229
|
if (bpApi) result.push(bpApi);
|
|
287
230
|
return result;
|
|
288
231
|
}, []);
|
|
289
232
|
};
|
|
290
|
-
|
|
291
233
|
return api;
|
|
292
234
|
};
|
|
293
|
-
|
|
294
235
|
proto.getPostponed = function getPostponed(...args) {
|
|
295
236
|
const running = this[kProcesses].running;
|
|
296
237
|
return running.reduce((result, p) => {
|
|
@@ -298,48 +239,37 @@ proto.getPostponed = function getPostponed(...args) {
|
|
|
298
239
|
return result;
|
|
299
240
|
}, []);
|
|
300
241
|
};
|
|
301
|
-
|
|
302
242
|
proto._start = function start() {
|
|
303
243
|
const {
|
|
304
244
|
ids,
|
|
305
245
|
executable,
|
|
306
246
|
postponed
|
|
307
247
|
} = this[kProcesses];
|
|
308
|
-
|
|
309
248
|
if (!ids.length) {
|
|
310
249
|
return this._complete('completed');
|
|
311
250
|
}
|
|
312
|
-
|
|
313
251
|
if (!executable.length) {
|
|
314
252
|
return this._complete('error', {
|
|
315
253
|
error: new Error('No executable process')
|
|
316
254
|
});
|
|
317
255
|
}
|
|
318
|
-
|
|
319
256
|
this[kStatus] = 'start';
|
|
320
|
-
|
|
321
257
|
for (const bp of executable) bp.init();
|
|
322
|
-
|
|
323
258
|
for (const bp of executable) bp.run();
|
|
324
|
-
|
|
325
259
|
postponed.splice(0);
|
|
326
260
|
this[kProcessesQ].assertConsumer(this[kMessageHandlers].onProcessMessage, {
|
|
327
261
|
prefetch: 1000,
|
|
328
262
|
consumerTag: `_definition-activity-${this.executionId}`
|
|
329
263
|
});
|
|
330
264
|
};
|
|
331
|
-
|
|
332
265
|
proto._activate = function activate(processList) {
|
|
333
266
|
this.broker.subscribeTmp('api', '#', this[kMessageHandlers].onApiMessage, {
|
|
334
267
|
noAck: true,
|
|
335
268
|
consumerTag: '_definition-api-consumer'
|
|
336
269
|
});
|
|
337
|
-
|
|
338
270
|
for (const bp of processList) this._activateProcess(bp);
|
|
339
|
-
|
|
340
271
|
this[kActivated] = true;
|
|
341
272
|
};
|
|
342
|
-
|
|
343
273
|
proto._activateProcess = function activateProcess(bp) {
|
|
344
274
|
const handlers = this[kMessageHandlers];
|
|
345
275
|
bp.broker.subscribeTmp('message', 'message.outbound', handlers.onMessageOutbound, {
|
|
@@ -372,35 +302,29 @@ proto._activateProcess = function activateProcess(bp) {
|
|
|
372
302
|
priority: 100
|
|
373
303
|
});
|
|
374
304
|
};
|
|
375
|
-
|
|
376
305
|
proto._onChildEvent = function onChildEvent(routingKey, originalMessage) {
|
|
377
306
|
const message = (0, _messageHelper.cloneMessage)(originalMessage);
|
|
378
307
|
const content = message.content;
|
|
379
308
|
const parent = content.parent = content.parent || {};
|
|
380
309
|
const isDirectChild = this[kProcesses].ids.indexOf(content.id) > -1;
|
|
381
|
-
|
|
382
310
|
if (isDirectChild) {
|
|
383
311
|
parent.executionId = this.executionId;
|
|
384
312
|
} else {
|
|
385
313
|
content.parent = (0, _messageHelper.pushParent)(parent, this);
|
|
386
314
|
}
|
|
387
|
-
|
|
388
|
-
|
|
315
|
+
this.broker.publish('event', routingKey, content, {
|
|
316
|
+
...message.properties,
|
|
389
317
|
mandatory: false
|
|
390
318
|
});
|
|
391
319
|
if (!isDirectChild) return;
|
|
392
320
|
this[kProcessesQ].queueMessage(message.fields, (0, _messageHelper.cloneContent)(content), message.properties);
|
|
393
321
|
};
|
|
394
|
-
|
|
395
322
|
proto._deactivate = function deactivate() {
|
|
396
323
|
this.broker.cancel('_definition-api-consumer');
|
|
397
324
|
this.broker.cancel(`_definition-activity-${this.executionId}`);
|
|
398
|
-
|
|
399
325
|
for (const bp of this[kProcesses].running) this._deactivateProcess(bp);
|
|
400
|
-
|
|
401
326
|
this[kActivated] = false;
|
|
402
327
|
};
|
|
403
|
-
|
|
404
328
|
proto._deactivateProcess = function deactivateProcess(bp) {
|
|
405
329
|
bp.broker.cancel('_definition-outbound-message-consumer');
|
|
406
330
|
bp.broker.cancel('_definition-activity-consumer');
|
|
@@ -409,7 +333,6 @@ proto._deactivateProcess = function deactivateProcess(bp) {
|
|
|
409
333
|
bp.broker.cancel('_definition-call-consumer');
|
|
410
334
|
bp.broker.cancel('_definition-call-cancel-consumer');
|
|
411
335
|
};
|
|
412
|
-
|
|
413
336
|
proto._onProcessMessage = function onProcessMessage(routingKey, message) {
|
|
414
337
|
const content = message.content;
|
|
415
338
|
const isRedelivered = message.fields.redelivered;
|
|
@@ -418,66 +341,55 @@ proto._onProcessMessage = function onProcessMessage(routingKey, message) {
|
|
|
418
341
|
inbound
|
|
419
342
|
} = content;
|
|
420
343
|
if (isRedelivered && message.properties.persistent === false) return;
|
|
421
|
-
|
|
422
344
|
switch (routingKey) {
|
|
423
345
|
case 'execution.stop':
|
|
424
346
|
{
|
|
425
347
|
message.ack();
|
|
426
348
|
return this._onStopped(message);
|
|
427
349
|
}
|
|
428
|
-
|
|
429
350
|
case 'process.leave':
|
|
430
351
|
{
|
|
431
352
|
return this._onProcessCompleted(message);
|
|
432
353
|
}
|
|
433
354
|
}
|
|
434
|
-
|
|
435
355
|
this._stateChangeMessage(message, true);
|
|
436
|
-
|
|
437
356
|
switch (routingKey) {
|
|
438
357
|
case 'process.enter':
|
|
439
358
|
this[kStatus] = 'executing';
|
|
440
359
|
break;
|
|
441
|
-
|
|
442
360
|
case 'process.discarded':
|
|
443
361
|
{
|
|
444
362
|
if (inbound && inbound.length) {
|
|
445
363
|
const calledFrom = inbound[0];
|
|
446
|
-
|
|
447
364
|
this._getProcessApi({
|
|
448
365
|
content: calledFrom
|
|
449
366
|
}).cancel({
|
|
450
367
|
executionId: calledFrom.executionId
|
|
451
368
|
});
|
|
452
369
|
}
|
|
453
|
-
|
|
454
370
|
break;
|
|
455
371
|
}
|
|
456
|
-
|
|
457
372
|
case 'process.end':
|
|
458
373
|
{
|
|
459
374
|
if (inbound && inbound.length) {
|
|
460
375
|
const calledFrom = inbound[0];
|
|
461
|
-
|
|
462
376
|
this._getProcessApi({
|
|
463
377
|
content: calledFrom
|
|
464
378
|
}).signal({
|
|
465
379
|
executionId: calledFrom.executionId,
|
|
466
|
-
output: {
|
|
380
|
+
output: {
|
|
381
|
+
...content.output
|
|
467
382
|
}
|
|
468
383
|
});
|
|
469
384
|
} else {
|
|
470
385
|
Object.assign(this.environment.output, content.output);
|
|
471
386
|
}
|
|
472
|
-
|
|
473
387
|
break;
|
|
474
388
|
}
|
|
475
|
-
|
|
476
389
|
case 'process.error':
|
|
477
390
|
{
|
|
478
391
|
if (inbound && inbound.length) {
|
|
479
392
|
const calledFrom = inbound[0];
|
|
480
|
-
|
|
481
393
|
this._getProcessApi({
|
|
482
394
|
content: calledFrom
|
|
483
395
|
}).sendApiMessage('error', {
|
|
@@ -491,33 +403,26 @@ proto._onProcessMessage = function onProcessMessage(routingKey, message) {
|
|
|
491
403
|
for (const bp of this[kProcesses].running.slice()) {
|
|
492
404
|
if (bp.id !== childId) bp.stop();
|
|
493
405
|
}
|
|
494
|
-
|
|
495
406
|
this._complete('error', {
|
|
496
407
|
error: content.error
|
|
497
408
|
});
|
|
498
409
|
}
|
|
499
|
-
|
|
500
410
|
break;
|
|
501
411
|
}
|
|
502
412
|
}
|
|
503
413
|
};
|
|
504
|
-
|
|
505
414
|
proto._stateChangeMessage = function stateChangeMessage(message, postponeMessage) {
|
|
506
415
|
let previousMsg;
|
|
507
416
|
const postponed = this[kProcesses].postponed;
|
|
508
417
|
const idx = postponed.findIndex(msg => msg.content.executionId === message.content.executionId);
|
|
509
|
-
|
|
510
418
|
if (idx > -1) {
|
|
511
419
|
previousMsg = postponed.splice(idx, 1)[0];
|
|
512
420
|
}
|
|
513
|
-
|
|
514
421
|
if (previousMsg) previousMsg.ack();
|
|
515
422
|
if (postponeMessage) postponed.push(message);
|
|
516
423
|
};
|
|
517
|
-
|
|
518
424
|
proto._onProcessCompleted = function onProcessCompleted(message) {
|
|
519
425
|
this._stateChangeMessage(message, false);
|
|
520
|
-
|
|
521
426
|
if (message.fields.redelivered) return message.ack();
|
|
522
427
|
const {
|
|
523
428
|
id,
|
|
@@ -525,62 +430,46 @@ proto._onProcessCompleted = function onProcessCompleted(message) {
|
|
|
525
430
|
type,
|
|
526
431
|
inbound
|
|
527
432
|
} = message.content;
|
|
528
|
-
|
|
529
433
|
this._debug(`left <${executionId} (${id})> (${type}), pending runs ${this.postponedCount}`);
|
|
530
|
-
|
|
531
434
|
if (inbound && inbound.length) {
|
|
532
435
|
const bp = this._removeProcessByExecutionId(executionId);
|
|
533
|
-
|
|
534
436
|
this._deactivateProcess(bp);
|
|
535
437
|
}
|
|
536
|
-
|
|
537
438
|
if (!this.postponedCount) {
|
|
538
439
|
message.ack();
|
|
539
|
-
|
|
540
440
|
this._complete('completed');
|
|
541
441
|
}
|
|
542
442
|
};
|
|
543
|
-
|
|
544
443
|
proto._onStopped = function onStopped(message) {
|
|
545
444
|
const running = this[kProcesses].running;
|
|
546
|
-
|
|
547
445
|
this._debug(`stop definition execution (stop process executions ${running.length})`);
|
|
548
|
-
|
|
549
446
|
this[kProcessesQ].close();
|
|
550
|
-
|
|
551
447
|
for (const bp of running.slice()) bp.stop();
|
|
552
|
-
|
|
553
448
|
this._deactivate();
|
|
554
|
-
|
|
555
449
|
this[kStopped] = true;
|
|
556
|
-
return this.broker.publish('execution', `execution.stopped.${this.executionId}`, (0, _messageHelper.cloneContent)(this[kExecuteMessage].content, {
|
|
450
|
+
return this.broker.publish('execution', `execution.stopped.${this.executionId}`, (0, _messageHelper.cloneContent)(this[kExecuteMessage].content, {
|
|
451
|
+
...message.content
|
|
557
452
|
}), {
|
|
558
453
|
type: 'stopped',
|
|
559
454
|
persistent: false
|
|
560
455
|
});
|
|
561
456
|
};
|
|
562
|
-
|
|
563
457
|
proto._onApiMessage = function onApiMessage(routingKey, message) {
|
|
564
458
|
const messageType = message.properties.type;
|
|
565
459
|
const delegate = message.properties.delegate;
|
|
566
|
-
|
|
567
460
|
if (delegate && this.id === message.content.id) {
|
|
568
461
|
const referenceId = (0, _getPropertyValue.default)(message, 'content.message.id');
|
|
569
|
-
|
|
570
462
|
this._startProcessesByMessage({
|
|
571
463
|
referenceId,
|
|
572
464
|
referenceType: messageType
|
|
573
465
|
});
|
|
574
466
|
}
|
|
575
|
-
|
|
576
467
|
if (delegate) {
|
|
577
468
|
for (const bp of this[kProcesses].running.slice()) {
|
|
578
469
|
bp.broker.publish('api', routingKey, (0, _messageHelper.cloneContent)(message.content), message.properties);
|
|
579
470
|
}
|
|
580
471
|
}
|
|
581
|
-
|
|
582
472
|
if (this.executionId !== message.content.executionId) return;
|
|
583
|
-
|
|
584
473
|
if (messageType === 'stop') {
|
|
585
474
|
this[kProcessesQ].queueMessage({
|
|
586
475
|
routingKey: 'execution.stop'
|
|
@@ -589,77 +478,59 @@ proto._onApiMessage = function onApiMessage(routingKey, message) {
|
|
|
589
478
|
});
|
|
590
479
|
}
|
|
591
480
|
};
|
|
592
|
-
|
|
593
481
|
proto._startProcessesByMessage = function startProcessesByMessage(reference) {
|
|
594
482
|
const {
|
|
595
483
|
processes: bps,
|
|
596
484
|
running
|
|
597
485
|
} = this[kProcesses];
|
|
598
486
|
if (bps.length < 2) return;
|
|
599
|
-
|
|
600
487
|
for (const bp of bps) {
|
|
601
488
|
if (bp.isExecutable) continue;
|
|
602
489
|
if (!bp.getStartActivities(reference).length) continue;
|
|
603
|
-
|
|
604
490
|
if (!bp.executionId) {
|
|
605
491
|
this._debug(`start <${bp.id}> by <${reference.referenceId}> (${reference.referenceType})`);
|
|
606
|
-
|
|
607
492
|
this._activateProcess(bp);
|
|
608
|
-
|
|
609
493
|
running.push(bp);
|
|
610
494
|
bp.init();
|
|
611
495
|
bp.run();
|
|
612
496
|
if (reference.referenceType === 'message') return;
|
|
613
497
|
continue;
|
|
614
498
|
}
|
|
615
|
-
|
|
616
499
|
this._debug(`start new <${bp.id}> by <${reference.referenceId}> (${reference.referenceType})`);
|
|
617
|
-
|
|
618
500
|
const targetProcess = this.context.getNewProcessById(bp.id);
|
|
619
|
-
|
|
620
501
|
this._activateProcess(targetProcess);
|
|
621
|
-
|
|
622
502
|
running.push(targetProcess);
|
|
623
503
|
targetProcess.init();
|
|
624
504
|
targetProcess.run();
|
|
625
505
|
if (reference.referenceType === 'message') return;
|
|
626
506
|
}
|
|
627
507
|
};
|
|
628
|
-
|
|
629
508
|
proto._onMessageOutbound = function onMessageOutbound(routingKey, message) {
|
|
630
509
|
const content = message.content;
|
|
631
510
|
const {
|
|
632
511
|
target,
|
|
633
512
|
source
|
|
634
513
|
} = content;
|
|
635
|
-
|
|
636
514
|
this._debug(`conveying message from <${source.processId}.${source.id}> to`, target.id ? `<${target.processId}.${target.id}>` : `<${target.processId}>`);
|
|
637
|
-
|
|
638
515
|
const targetProcesses = this.getProcessesById(target.processId);
|
|
639
516
|
if (!targetProcesses.length) return;
|
|
640
517
|
let targetProcess, found;
|
|
641
|
-
|
|
642
518
|
for (const bp of targetProcesses) {
|
|
643
519
|
if (!bp.executionId) {
|
|
644
520
|
targetProcess = bp;
|
|
645
521
|
continue;
|
|
646
522
|
}
|
|
647
|
-
|
|
648
523
|
bp.sendMessage(message);
|
|
649
524
|
found = true;
|
|
650
525
|
}
|
|
651
|
-
|
|
652
526
|
if (found) return;
|
|
653
527
|
targetProcess = targetProcess || this.context.getNewProcessById(target.processId);
|
|
654
|
-
|
|
655
528
|
this._activateProcess(targetProcess);
|
|
656
|
-
|
|
657
529
|
this[kProcesses].running.push(targetProcess);
|
|
658
530
|
targetProcess.init();
|
|
659
531
|
targetProcess.run();
|
|
660
532
|
targetProcess.sendMessage(message);
|
|
661
533
|
};
|
|
662
|
-
|
|
663
534
|
proto._onCallActivity = function onCallActivity(routingKey, message) {
|
|
664
535
|
const content = message.content;
|
|
665
536
|
const {
|
|
@@ -671,11 +542,9 @@ proto._onCallActivity = function onCallActivity(routingKey, message) {
|
|
|
671
542
|
} = content;
|
|
672
543
|
if (!calledElement) return;
|
|
673
544
|
const bpExecutionId = `${(0, _shared.brokerSafeId)(calledElement)}_${fromExecutionId}`;
|
|
674
|
-
|
|
675
545
|
if (content.isRecovered) {
|
|
676
546
|
if (this.getProcessByExecutionId(bpExecutionId)) return;
|
|
677
547
|
}
|
|
678
|
-
|
|
679
548
|
const targetProcess = this.context.getNewProcessById(calledElement, {
|
|
680
549
|
settings: {
|
|
681
550
|
calledFrom: (0, _messageHelper.cloneContent)({
|
|
@@ -687,18 +556,14 @@ proto._onCallActivity = function onCallActivity(routingKey, message) {
|
|
|
687
556
|
}
|
|
688
557
|
});
|
|
689
558
|
if (!targetProcess) return;
|
|
690
|
-
|
|
691
559
|
this._debug(`call from <${fromParent.id}.${fromId}> to <${calledElement}>`);
|
|
692
|
-
|
|
693
560
|
this._activateProcess(targetProcess);
|
|
694
|
-
|
|
695
561
|
this[kProcesses].running.push(targetProcess);
|
|
696
562
|
targetProcess.init(bpExecutionId);
|
|
697
563
|
targetProcess.run({
|
|
698
564
|
inbound: [(0, _messageHelper.cloneContent)(content)]
|
|
699
565
|
});
|
|
700
566
|
};
|
|
701
|
-
|
|
702
567
|
proto._onCancelCallActivity = function onCancelCallActivity(routingKey, message) {
|
|
703
568
|
const {
|
|
704
569
|
calledElement,
|
|
@@ -710,21 +575,16 @@ proto._onCancelCallActivity = function onCancelCallActivity(routingKey, message)
|
|
|
710
575
|
const bpExecutionId = `${(0, _shared.brokerSafeId)(calledElement)}_${fromExecutionId}`;
|
|
711
576
|
const targetProcess = this.getProcessByExecutionId(bpExecutionId);
|
|
712
577
|
if (!targetProcess) return;
|
|
713
|
-
|
|
714
578
|
this._debug(`cancel call from <${fromParent.id}.${fromId}> to <${calledElement}>`);
|
|
715
|
-
|
|
716
579
|
targetProcess.getApi().discard();
|
|
717
580
|
};
|
|
718
|
-
|
|
719
581
|
proto._onDelegateMessage = function onDelegateMessage(routingKey, executeMessage) {
|
|
720
582
|
const content = executeMessage.content;
|
|
721
583
|
const messageType = executeMessage.properties.type;
|
|
722
584
|
const delegateMessage = executeMessage.content.message;
|
|
723
585
|
const reference = this.context.getActivityById(delegateMessage.id);
|
|
724
586
|
const message = reference && reference.resolve(executeMessage);
|
|
725
|
-
|
|
726
587
|
this._debug(`<${reference ? `${messageType} ${delegateMessage.id}>` : `anonymous ${messageType}`} event received from <${content.parent.id}.${content.id}>. Delegating.`);
|
|
727
|
-
|
|
728
588
|
this.getApi().sendApiMessage(messageType, {
|
|
729
589
|
source: {
|
|
730
590
|
id: content.id,
|
|
@@ -744,27 +604,24 @@ proto._onDelegateMessage = function onDelegateMessage(routingKey, executeMessage
|
|
|
744
604
|
type: messageType
|
|
745
605
|
});
|
|
746
606
|
};
|
|
747
|
-
|
|
748
607
|
proto._removeProcessByExecutionId = function removeProcessByExecutionId(processExecutionId) {
|
|
749
608
|
const running = this[kProcesses].running;
|
|
750
609
|
const idx = running.findIndex(p => p.executionId === processExecutionId);
|
|
751
610
|
if (idx === -1) return;
|
|
752
611
|
return running.splice(idx, 1)[0];
|
|
753
612
|
};
|
|
754
|
-
|
|
755
613
|
proto._complete = function complete(completionType, content, options) {
|
|
756
614
|
this._deactivate();
|
|
757
|
-
|
|
758
615
|
const stateMessage = this[kExecuteMessage];
|
|
759
|
-
|
|
760
616
|
this._debug(`definition execution ${completionType} in ${Date.now() - stateMessage.properties.timestamp}ms`);
|
|
761
|
-
|
|
762
617
|
if (!content) content = this._createMessage();
|
|
763
618
|
this[kCompleted] = true;
|
|
764
619
|
this[kStatus] = completionType;
|
|
765
620
|
this.broker.deleteQueue(this[kProcessesQ].name);
|
|
766
|
-
return this.broker.publish('execution', `execution.${completionType}.${this.executionId}`, {
|
|
767
|
-
|
|
621
|
+
return this.broker.publish('execution', `execution.${completionType}.${this.executionId}`, {
|
|
622
|
+
...stateMessage.content,
|
|
623
|
+
output: {
|
|
624
|
+
...this.environment.output
|
|
768
625
|
},
|
|
769
626
|
...content,
|
|
770
627
|
state: completionType
|
|
@@ -774,7 +631,6 @@ proto._complete = function complete(completionType, content, options) {
|
|
|
774
631
|
...options
|
|
775
632
|
});
|
|
776
633
|
};
|
|
777
|
-
|
|
778
634
|
proto._createMessage = function createMessage(content = {}) {
|
|
779
635
|
return {
|
|
780
636
|
id: this.id,
|
|
@@ -784,30 +640,24 @@ proto._createMessage = function createMessage(content = {}) {
|
|
|
784
640
|
...content
|
|
785
641
|
};
|
|
786
642
|
};
|
|
787
|
-
|
|
788
643
|
proto._getProcessApi = function getProcessApi(message) {
|
|
789
644
|
const content = message.content;
|
|
790
|
-
|
|
791
645
|
let api = this._getProcessApiByExecutionId(content.executionId, message);
|
|
792
|
-
|
|
793
646
|
if (api) return api;
|
|
794
647
|
if (!content.parent) return;
|
|
795
648
|
api = this._getProcessApiByExecutionId(content.parent.executionId, message);
|
|
796
649
|
if (api) return api;
|
|
797
650
|
if (!content.parent.path) return;
|
|
798
|
-
|
|
799
651
|
for (const pp of content.parent.path) {
|
|
800
652
|
api = this._getProcessApiByExecutionId(pp.executionId, message);
|
|
801
653
|
if (api) return api;
|
|
802
654
|
}
|
|
803
655
|
};
|
|
804
|
-
|
|
805
656
|
proto._getProcessApiByExecutionId = function getProcessApiByExecutionId(parentExecutionId, message) {
|
|
806
657
|
const processInstance = this.getProcessByExecutionId(parentExecutionId);
|
|
807
658
|
if (!processInstance) return;
|
|
808
659
|
return processInstance.getApi(message);
|
|
809
660
|
};
|
|
810
|
-
|
|
811
661
|
proto._debug = function debug(logMessage) {
|
|
812
662
|
this[kParent].logger.debug(`<${this.executionId} (${this.id})> ${logMessage}`);
|
|
813
663
|
};
|