bpmn-elements 7.0.0 → 8.0.0
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 +13 -0
- package/dist/src/Context.js +50 -40
- package/dist/src/Environment.js +39 -19
- package/dist/src/MessageFormatter.js +11 -11
- package/dist/src/activity/Activity.js +91 -91
- package/dist/src/activity/ActivityExecution.js +35 -35
- package/dist/src/definition/Definition.js +50 -50
- package/dist/src/definition/DefinitionExecution.js +114 -125
- package/dist/src/eventDefinitions/CancelEventDefinition.js +16 -16
- package/dist/src/eventDefinitions/CompensateEventDefinition.js +24 -24
- package/dist/src/eventDefinitions/ConditionalEventDefinition.js +8 -8
- package/dist/src/eventDefinitions/ErrorEventDefinition.js +26 -26
- package/dist/src/eventDefinitions/EscalationEventDefinition.js +20 -20
- package/dist/src/eventDefinitions/EventDefinitionExecution.js +14 -14
- package/dist/src/eventDefinitions/LinkEventDefinition.js +15 -15
- package/dist/src/eventDefinitions/MessageEventDefinition.js +23 -23
- package/dist/src/eventDefinitions/SignalEventDefinition.js +24 -24
- package/dist/src/eventDefinitions/TimerEventDefinition.js +21 -21
- package/dist/src/events/BoundaryEvent.js +20 -20
- package/dist/src/events/EndEvent.js +3 -3
- package/dist/src/events/IntermediateCatchEvent.js +3 -3
- package/dist/src/events/IntermediateThrowEvent.js +3 -3
- package/dist/src/events/StartEvent.js +9 -9
- package/dist/src/flows/Association.js +7 -7
- package/dist/src/flows/MessageFlow.js +9 -9
- package/dist/src/flows/SequenceFlow.js +7 -7
- package/dist/src/gateways/EventBasedGateway.js +11 -11
- package/dist/src/io/InputOutputSpecification.js +4 -4
- package/dist/src/io/Properties.js +9 -9
- package/dist/src/process/Process.js +64 -61
- package/dist/src/process/ProcessExecution.js +93 -90
- package/dist/src/tasks/ReceiveTask.js +16 -16
- package/dist/src/tasks/SubProcess.js +16 -18
- package/package.json +9 -9
- package/src/Context.js +48 -40
- package/src/Environment.js +48 -20
- package/src/EventBroker.js +1 -1
- package/src/MessageFormatter.js +11 -11
- package/src/activity/Activity.js +91 -91
- package/src/activity/ActivityExecution.js +34 -34
- package/src/definition/Definition.js +51 -50
- package/src/definition/DefinitionExecution.js +111 -113
- package/src/eventDefinitions/CancelEventDefinition.js +16 -16
- package/src/eventDefinitions/CompensateEventDefinition.js +25 -24
- package/src/eventDefinitions/ConditionalEventDefinition.js +8 -8
- package/src/eventDefinitions/ErrorEventDefinition.js +26 -26
- package/src/eventDefinitions/EscalationEventDefinition.js +20 -20
- package/src/eventDefinitions/EventDefinitionExecution.js +14 -14
- package/src/eventDefinitions/LinkEventDefinition.js +15 -15
- package/src/eventDefinitions/MessageEventDefinition.js +23 -23
- package/src/eventDefinitions/SignalEventDefinition.js +24 -24
- package/src/eventDefinitions/TimerEventDefinition.js +21 -21
- package/src/events/BoundaryEvent.js +20 -20
- package/src/events/EndEvent.js +3 -3
- package/src/events/IntermediateCatchEvent.js +3 -3
- package/src/events/IntermediateThrowEvent.js +3 -3
- package/src/events/StartEvent.js +9 -9
- package/src/flows/Association.js +7 -7
- package/src/flows/MessageFlow.js +9 -9
- package/src/flows/SequenceFlow.js +7 -7
- package/src/gateways/EventBasedGateway.js +11 -11
- package/src/io/BpmnIO.js +5 -1
- package/src/io/InputOutputSpecification.js +4 -4
- package/src/io/Properties.js +9 -9
- package/src/process/Process.js +62 -58
- package/src/process/ProcessExecution.js +86 -88
- package/src/tasks/ReceiveTask.js +16 -16
- package/src/tasks/SubProcess.js +16 -16
|
@@ -15,48 +15,53 @@ var _messageHelper = require("../messageHelper");
|
|
|
15
15
|
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
18
|
+
const kActivated = Symbol.for('activated');
|
|
19
|
+
const kProcessesQ = Symbol.for('processesQ');
|
|
20
|
+
const kCompleted = Symbol.for('completed');
|
|
21
|
+
const kExecuteMessage = Symbol.for('executeMessage');
|
|
22
|
+
const kMessageHandlers = Symbol.for('messageHandlers');
|
|
23
|
+
const kParent = Symbol.for('definition');
|
|
24
|
+
const kProcesses = Symbol.for('processes');
|
|
25
|
+
const kStatus = Symbol.for('status');
|
|
26
|
+
const kStopped = Symbol.for('stopped');
|
|
27
27
|
|
|
28
28
|
function DefinitionExecution(definition, context) {
|
|
29
29
|
const broker = definition.broker;
|
|
30
|
-
this[
|
|
30
|
+
this[kParent] = definition;
|
|
31
31
|
this.id = definition.id;
|
|
32
32
|
this.type = definition.type;
|
|
33
33
|
this.broker = broker;
|
|
34
|
-
this.environment = definition.environment;
|
|
34
|
+
const environment = this.environment = definition.environment;
|
|
35
35
|
this.context = context;
|
|
36
|
-
const processes =
|
|
37
|
-
|
|
36
|
+
const processes = context.getProcesses();
|
|
37
|
+
const ids = [];
|
|
38
|
+
const executable = [];
|
|
39
|
+
|
|
40
|
+
for (const bp of processes) {
|
|
41
|
+
bp.environment.assignVariables(environment.variables);
|
|
42
|
+
bp.environment.assignSettings(environment.settings);
|
|
43
|
+
ids.push(bp.id);
|
|
44
|
+
if (bp.isExecutable) executable.push(bp);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
this[kProcesses] = {
|
|
38
48
|
processes,
|
|
39
49
|
running: [],
|
|
40
|
-
ids
|
|
41
|
-
|
|
42
|
-
}) => childId),
|
|
43
|
-
executable: context.getExecutableProcesses(),
|
|
50
|
+
ids,
|
|
51
|
+
executable,
|
|
44
52
|
postponed: []
|
|
45
53
|
};
|
|
46
54
|
broker.assertExchange('execution', 'topic', {
|
|
47
55
|
autoDelete: false,
|
|
48
56
|
durable: true
|
|
49
57
|
});
|
|
50
|
-
broker.assertQueue('activity-q', {
|
|
51
|
-
autoDelete: false,
|
|
52
|
-
durable: false
|
|
53
|
-
});
|
|
54
|
-
this[completedSymbol] = false;
|
|
55
|
-
this[stoppedSymbol] = false;
|
|
56
|
-
this[activatedSymbol] = false;
|
|
57
|
-
this[statusSymbol] = 'init';
|
|
58
58
|
this.executionId = undefined;
|
|
59
|
-
this[
|
|
59
|
+
this[kCompleted] = false;
|
|
60
|
+
this[kStopped] = false;
|
|
61
|
+
this[kActivated] = false;
|
|
62
|
+
this[kStatus] = 'init';
|
|
63
|
+
this[kProcessesQ] = undefined;
|
|
64
|
+
this[kMessageHandlers] = {
|
|
60
65
|
onApiMessage: this._onApiMessage.bind(this),
|
|
61
66
|
onCallActivity: this._onCallActivity.bind(this),
|
|
62
67
|
onCancelCallActivity: this._onCancelCallActivity.bind(this),
|
|
@@ -72,7 +77,7 @@ Object.defineProperty(proto, 'stopped', {
|
|
|
72
77
|
enumerable: true,
|
|
73
78
|
|
|
74
79
|
get() {
|
|
75
|
-
return this[
|
|
80
|
+
return this[kStopped];
|
|
76
81
|
}
|
|
77
82
|
|
|
78
83
|
});
|
|
@@ -80,7 +85,7 @@ Object.defineProperty(proto, 'completed', {
|
|
|
80
85
|
enumerable: true,
|
|
81
86
|
|
|
82
87
|
get() {
|
|
83
|
-
return this[
|
|
88
|
+
return this[kCompleted];
|
|
84
89
|
}
|
|
85
90
|
|
|
86
91
|
});
|
|
@@ -88,7 +93,7 @@ Object.defineProperty(proto, 'status', {
|
|
|
88
93
|
enumerable: true,
|
|
89
94
|
|
|
90
95
|
get() {
|
|
91
|
-
return this[
|
|
96
|
+
return this[kStatus];
|
|
92
97
|
}
|
|
93
98
|
|
|
94
99
|
});
|
|
@@ -96,19 +101,19 @@ Object.defineProperty(proto, 'processes', {
|
|
|
96
101
|
enumerable: true,
|
|
97
102
|
|
|
98
103
|
get() {
|
|
99
|
-
return this[
|
|
104
|
+
return this[kProcesses].running;
|
|
100
105
|
}
|
|
101
106
|
|
|
102
107
|
});
|
|
103
108
|
Object.defineProperty(proto, 'postponedCount', {
|
|
104
109
|
get() {
|
|
105
|
-
return this[
|
|
110
|
+
return this[kProcesses].postponed.length;
|
|
106
111
|
}
|
|
107
112
|
|
|
108
113
|
});
|
|
109
114
|
Object.defineProperty(proto, 'isRunning', {
|
|
110
115
|
get() {
|
|
111
|
-
return this[
|
|
116
|
+
return this[kActivated];
|
|
112
117
|
}
|
|
113
118
|
|
|
114
119
|
});
|
|
@@ -118,12 +123,12 @@ proto.execute = function execute(executeMessage) {
|
|
|
118
123
|
const content = executeMessage.content;
|
|
119
124
|
const executionId = this.executionId = content.executionId;
|
|
120
125
|
if (!executionId) throw new Error('Definition execution requires execution id');
|
|
121
|
-
this[
|
|
126
|
+
this[kExecuteMessage] = (0, _messageHelper.cloneMessage)(executeMessage, {
|
|
122
127
|
executionId,
|
|
123
128
|
state: 'start'
|
|
124
129
|
});
|
|
125
|
-
this[
|
|
126
|
-
this[
|
|
130
|
+
this[kStopped] = false;
|
|
131
|
+
this[kProcessesQ] = this.broker.assertQueue(`execute-${executionId}-q`, {
|
|
127
132
|
durable: true,
|
|
128
133
|
autoDelete: false
|
|
129
134
|
});
|
|
@@ -135,7 +140,7 @@ proto.execute = function execute(executeMessage) {
|
|
|
135
140
|
const {
|
|
136
141
|
running,
|
|
137
142
|
executable
|
|
138
|
-
} = this[
|
|
143
|
+
} = this[kProcesses];
|
|
139
144
|
|
|
140
145
|
if (content.processId) {
|
|
141
146
|
const startWithProcess = this.getProcessById(content.processId);
|
|
@@ -158,33 +163,22 @@ proto.execute = function execute(executeMessage) {
|
|
|
158
163
|
};
|
|
159
164
|
|
|
160
165
|
proto.resume = function resume() {
|
|
161
|
-
this._debug(`resume ${this
|
|
166
|
+
this._debug(`resume ${this[kStatus]} definition execution`);
|
|
162
167
|
|
|
163
|
-
if (this
|
|
168
|
+
if (this[kCompleted]) return this._complete('completed');
|
|
164
169
|
const {
|
|
165
170
|
running,
|
|
166
171
|
postponed
|
|
167
|
-
} = this[
|
|
172
|
+
} = this[kProcesses];
|
|
168
173
|
|
|
169
174
|
this._activate(running);
|
|
170
175
|
|
|
171
176
|
postponed.splice(0);
|
|
172
|
-
this[
|
|
177
|
+
this[kProcessesQ].consume(this[kMessageHandlers].onProcessMessage, {
|
|
173
178
|
prefetch: 1000,
|
|
174
179
|
consumerTag: `_definition-activity-${this.executionId}`
|
|
175
180
|
});
|
|
176
|
-
if (this
|
|
177
|
-
|
|
178
|
-
switch (this.status) {
|
|
179
|
-
case 'init':
|
|
180
|
-
return this._start();
|
|
181
|
-
|
|
182
|
-
case 'executing':
|
|
183
|
-
{
|
|
184
|
-
if (!this.postponedCount) return this._complete('completed');
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
181
|
+
if (this[kCompleted]) return;
|
|
188
182
|
|
|
189
183
|
for (const bp of running) bp.resume();
|
|
190
184
|
};
|
|
@@ -192,20 +186,32 @@ proto.resume = function resume() {
|
|
|
192
186
|
proto.recover = function recover(state) {
|
|
193
187
|
if (!state) return this;
|
|
194
188
|
this.executionId = state.executionId;
|
|
195
|
-
this[
|
|
196
|
-
this[
|
|
197
|
-
this[
|
|
189
|
+
this[kStopped] = state.stopped;
|
|
190
|
+
this[kCompleted] = state.completed;
|
|
191
|
+
this[kStatus] = state.status;
|
|
198
192
|
|
|
199
|
-
this._debug(`recover ${this
|
|
193
|
+
this._debug(`recover ${this[kStatus]} definition execution`);
|
|
200
194
|
|
|
201
|
-
const running = this[
|
|
195
|
+
const running = this[kProcesses].running;
|
|
202
196
|
running.splice(0);
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
197
|
+
const ids = [];
|
|
198
|
+
|
|
199
|
+
for (const bpState of state.processes) {
|
|
200
|
+
const bpid = bpState.id;
|
|
201
|
+
let bp;
|
|
202
|
+
|
|
203
|
+
if (ids.indexOf(bpid) > -1) {
|
|
204
|
+
bp = this.context.getNewProcessById(bpid);
|
|
205
|
+
} else {
|
|
206
|
+
bp = this.getProcessById(bpid);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (!bp) return;
|
|
210
|
+
ids.push(bpid);
|
|
211
|
+
bp.recover(bpState);
|
|
212
|
+
running.push(bp);
|
|
213
|
+
}
|
|
214
|
+
|
|
209
215
|
return this;
|
|
210
216
|
};
|
|
211
217
|
|
|
@@ -217,7 +223,7 @@ proto.getProcesses = function getProcesses() {
|
|
|
217
223
|
const {
|
|
218
224
|
running,
|
|
219
225
|
processes
|
|
220
|
-
} = this[
|
|
226
|
+
} = this[kProcesses];
|
|
221
227
|
const result = running.slice();
|
|
222
228
|
|
|
223
229
|
for (const bp of processes) {
|
|
@@ -236,31 +242,31 @@ proto.getProcessesById = function getProcessesById(processId) {
|
|
|
236
242
|
};
|
|
237
243
|
|
|
238
244
|
proto.getProcessByExecutionId = function getProcessByExecutionId(processExecutionId) {
|
|
239
|
-
const running = this[
|
|
245
|
+
const running = this[kProcesses].running;
|
|
240
246
|
return running.find(bp => bp.executionId === processExecutionId);
|
|
241
247
|
};
|
|
242
248
|
|
|
243
249
|
proto.getRunningProcesses = function getRunningProcesses() {
|
|
244
|
-
const running = this[
|
|
250
|
+
const running = this[kProcesses].running;
|
|
245
251
|
return running.filter(bp => bp.executionId);
|
|
246
252
|
};
|
|
247
253
|
|
|
248
254
|
proto.getExecutableProcesses = function getExecutableProcesses() {
|
|
249
|
-
return this[
|
|
255
|
+
return this[kProcesses].executable.slice();
|
|
250
256
|
};
|
|
251
257
|
|
|
252
258
|
proto.getState = function getState() {
|
|
253
259
|
return {
|
|
254
260
|
executionId: this.executionId,
|
|
255
|
-
stopped: this
|
|
256
|
-
completed: this
|
|
257
|
-
status: this
|
|
258
|
-
processes: this[
|
|
261
|
+
stopped: this[kStopped],
|
|
262
|
+
completed: this[kCompleted],
|
|
263
|
+
status: this[kStatus],
|
|
264
|
+
processes: this[kProcesses].running.map(bp => bp.getState())
|
|
259
265
|
};
|
|
260
266
|
};
|
|
261
267
|
|
|
262
268
|
proto.getApi = function getApi(apiMessage) {
|
|
263
|
-
if (!apiMessage) apiMessage = this[
|
|
269
|
+
if (!apiMessage) apiMessage = this[kExecuteMessage] || {
|
|
264
270
|
content: this._createMessage()
|
|
265
271
|
};
|
|
266
272
|
const content = apiMessage.content;
|
|
@@ -270,7 +276,7 @@ proto.getApi = function getApi(apiMessage) {
|
|
|
270
276
|
}
|
|
271
277
|
|
|
272
278
|
const api = (0, _Api.DefinitionApi)(this.broker, apiMessage);
|
|
273
|
-
const postponed = this[
|
|
279
|
+
const postponed = this[kProcesses].postponed;
|
|
274
280
|
const self = this;
|
|
275
281
|
|
|
276
282
|
api.getExecuting = function getExecuting() {
|
|
@@ -286,7 +292,7 @@ proto.getApi = function getApi(apiMessage) {
|
|
|
286
292
|
};
|
|
287
293
|
|
|
288
294
|
proto.getPostponed = function getPostponed(...args) {
|
|
289
|
-
const running = this[
|
|
295
|
+
const running = this[kProcesses].running;
|
|
290
296
|
return running.reduce((result, p) => {
|
|
291
297
|
result = result.concat(p.getPostponed(...args));
|
|
292
298
|
return result;
|
|
@@ -298,10 +304,10 @@ proto._start = function start() {
|
|
|
298
304
|
ids,
|
|
299
305
|
executable,
|
|
300
306
|
postponed
|
|
301
|
-
} = this[
|
|
307
|
+
} = this[kProcesses];
|
|
302
308
|
|
|
303
309
|
if (!ids.length) {
|
|
304
|
-
return this.
|
|
310
|
+
return this._complete('completed');
|
|
305
311
|
}
|
|
306
312
|
|
|
307
313
|
if (!executable.length) {
|
|
@@ -310,32 +316,32 @@ proto._start = function start() {
|
|
|
310
316
|
});
|
|
311
317
|
}
|
|
312
318
|
|
|
313
|
-
this[
|
|
319
|
+
this[kStatus] = 'start';
|
|
314
320
|
|
|
315
321
|
for (const bp of executable) bp.init();
|
|
316
322
|
|
|
317
323
|
for (const bp of executable) bp.run();
|
|
318
324
|
|
|
319
325
|
postponed.splice(0);
|
|
320
|
-
this[
|
|
326
|
+
this[kProcessesQ].assertConsumer(this[kMessageHandlers].onProcessMessage, {
|
|
321
327
|
prefetch: 1000,
|
|
322
328
|
consumerTag: `_definition-activity-${this.executionId}`
|
|
323
329
|
});
|
|
324
330
|
};
|
|
325
331
|
|
|
326
332
|
proto._activate = function activate(processList) {
|
|
327
|
-
this.broker.subscribeTmp('api', '#', this[
|
|
333
|
+
this.broker.subscribeTmp('api', '#', this[kMessageHandlers].onApiMessage, {
|
|
328
334
|
noAck: true,
|
|
329
335
|
consumerTag: '_definition-api-consumer'
|
|
330
336
|
});
|
|
331
337
|
|
|
332
338
|
for (const bp of processList) this._activateProcess(bp);
|
|
333
339
|
|
|
334
|
-
this[
|
|
340
|
+
this[kActivated] = true;
|
|
335
341
|
};
|
|
336
342
|
|
|
337
343
|
proto._activateProcess = function activateProcess(bp) {
|
|
338
|
-
const handlers = this[
|
|
344
|
+
const handlers = this[kMessageHandlers];
|
|
339
345
|
bp.broker.subscribeTmp('message', 'message.outbound', handlers.onMessageOutbound, {
|
|
340
346
|
noAck: true,
|
|
341
347
|
consumerTag: '_definition-outbound-message-consumer'
|
|
@@ -371,7 +377,7 @@ proto._onChildEvent = function onChildEvent(routingKey, originalMessage) {
|
|
|
371
377
|
const message = (0, _messageHelper.cloneMessage)(originalMessage);
|
|
372
378
|
const content = message.content;
|
|
373
379
|
const parent = content.parent = content.parent || {};
|
|
374
|
-
const isDirectChild = this[
|
|
380
|
+
const isDirectChild = this[kProcesses].ids.indexOf(content.id) > -1;
|
|
375
381
|
|
|
376
382
|
if (isDirectChild) {
|
|
377
383
|
parent.executionId = this.executionId;
|
|
@@ -383,16 +389,16 @@ proto._onChildEvent = function onChildEvent(routingKey, originalMessage) {
|
|
|
383
389
|
mandatory: false
|
|
384
390
|
});
|
|
385
391
|
if (!isDirectChild) return;
|
|
386
|
-
this[
|
|
392
|
+
this[kProcessesQ].queueMessage(message.fields, (0, _messageHelper.cloneContent)(content), message.properties);
|
|
387
393
|
};
|
|
388
394
|
|
|
389
395
|
proto._deactivate = function deactivate() {
|
|
390
396
|
this.broker.cancel('_definition-api-consumer');
|
|
391
397
|
this.broker.cancel(`_definition-activity-${this.executionId}`);
|
|
392
398
|
|
|
393
|
-
for (const bp of this[
|
|
399
|
+
for (const bp of this[kProcesses].running) this._deactivateProcess(bp);
|
|
394
400
|
|
|
395
|
-
this[
|
|
401
|
+
this[kActivated] = false;
|
|
396
402
|
};
|
|
397
403
|
|
|
398
404
|
proto._deactivateProcess = function deactivateProcess(bp) {
|
|
@@ -409,7 +415,6 @@ proto._onProcessMessage = function onProcessMessage(routingKey, message) {
|
|
|
409
415
|
const isRedelivered = message.fields.redelivered;
|
|
410
416
|
const {
|
|
411
417
|
id: childId,
|
|
412
|
-
executionId: childExecutionId,
|
|
413
418
|
inbound
|
|
414
419
|
} = content;
|
|
415
420
|
if (isRedelivered && message.properties.persistent === false) return;
|
|
@@ -417,12 +422,8 @@ proto._onProcessMessage = function onProcessMessage(routingKey, message) {
|
|
|
417
422
|
switch (routingKey) {
|
|
418
423
|
case 'execution.stop':
|
|
419
424
|
{
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
return this._onStopped(message);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
break;
|
|
425
|
+
message.ack();
|
|
426
|
+
return this._onStopped(message);
|
|
426
427
|
}
|
|
427
428
|
|
|
428
429
|
case 'process.leave':
|
|
@@ -434,9 +435,8 @@ proto._onProcessMessage = function onProcessMessage(routingKey, message) {
|
|
|
434
435
|
this._stateChangeMessage(message, true);
|
|
435
436
|
|
|
436
437
|
switch (routingKey) {
|
|
437
|
-
case 'process.discard':
|
|
438
438
|
case 'process.enter':
|
|
439
|
-
this[
|
|
439
|
+
this[kStatus] = 'executing';
|
|
440
440
|
break;
|
|
441
441
|
|
|
442
442
|
case 'process.discarded':
|
|
@@ -488,7 +488,7 @@ proto._onProcessMessage = function onProcessMessage(routingKey, message) {
|
|
|
488
488
|
type: 'error'
|
|
489
489
|
});
|
|
490
490
|
} else {
|
|
491
|
-
for (const bp of this[
|
|
491
|
+
for (const bp of this[kProcesses].running.slice()) {
|
|
492
492
|
if (bp.id !== childId) bp.stop();
|
|
493
493
|
}
|
|
494
494
|
|
|
@@ -504,7 +504,7 @@ proto._onProcessMessage = function onProcessMessage(routingKey, message) {
|
|
|
504
504
|
|
|
505
505
|
proto._stateChangeMessage = function stateChangeMessage(message, postponeMessage) {
|
|
506
506
|
let previousMsg;
|
|
507
|
-
const postponed = this[
|
|
507
|
+
const postponed = this[kProcesses].postponed;
|
|
508
508
|
const idx = postponed.findIndex(msg => msg.content.executionId === message.content.executionId);
|
|
509
509
|
|
|
510
510
|
if (idx > -1) {
|
|
@@ -542,18 +542,18 @@ proto._onProcessCompleted = function onProcessCompleted(message) {
|
|
|
542
542
|
};
|
|
543
543
|
|
|
544
544
|
proto._onStopped = function onStopped(message) {
|
|
545
|
-
const running = this[
|
|
545
|
+
const running = this[kProcesses].running;
|
|
546
546
|
|
|
547
547
|
this._debug(`stop definition execution (stop process executions ${running.length})`);
|
|
548
548
|
|
|
549
|
-
this[
|
|
550
|
-
|
|
551
|
-
this._deactivate();
|
|
549
|
+
this[kProcessesQ].close();
|
|
552
550
|
|
|
553
551
|
for (const bp of running.slice()) bp.stop();
|
|
554
552
|
|
|
555
|
-
this
|
|
556
|
-
|
|
553
|
+
this._deactivate();
|
|
554
|
+
|
|
555
|
+
this[kStopped] = true;
|
|
556
|
+
return this.broker.publish('execution', `execution.stopped.${this.executionId}`, (0, _messageHelper.cloneContent)(this[kExecuteMessage].content, { ...message.content
|
|
557
557
|
}), {
|
|
558
558
|
type: 'stopped',
|
|
559
559
|
persistent: false
|
|
@@ -574,7 +574,7 @@ proto._onApiMessage = function onApiMessage(routingKey, message) {
|
|
|
574
574
|
}
|
|
575
575
|
|
|
576
576
|
if (delegate) {
|
|
577
|
-
for (const bp of this[
|
|
577
|
+
for (const bp of this[kProcesses].running.slice()) {
|
|
578
578
|
bp.broker.publish('api', routingKey, (0, _messageHelper.cloneContent)(message.content), message.properties);
|
|
579
579
|
}
|
|
580
580
|
}
|
|
@@ -582,7 +582,7 @@ proto._onApiMessage = function onApiMessage(routingKey, message) {
|
|
|
582
582
|
if (this.executionId !== message.content.executionId) return;
|
|
583
583
|
|
|
584
584
|
if (messageType === 'stop') {
|
|
585
|
-
this[
|
|
585
|
+
this[kProcessesQ].queueMessage({
|
|
586
586
|
routingKey: 'execution.stop'
|
|
587
587
|
}, (0, _messageHelper.cloneContent)(message.content), {
|
|
588
588
|
persistent: false
|
|
@@ -594,7 +594,7 @@ proto._startProcessesByMessage = function startProcessesByMessage(reference) {
|
|
|
594
594
|
const {
|
|
595
595
|
processes: bps,
|
|
596
596
|
running
|
|
597
|
-
} = this[
|
|
597
|
+
} = this[kProcesses];
|
|
598
598
|
if (bps.length < 2) return;
|
|
599
599
|
|
|
600
600
|
for (const bp of bps) {
|
|
@@ -654,7 +654,7 @@ proto._onMessageOutbound = function onMessageOutbound(routingKey, message) {
|
|
|
654
654
|
|
|
655
655
|
this._activateProcess(targetProcess);
|
|
656
656
|
|
|
657
|
-
this[
|
|
657
|
+
this[kProcesses].running.push(targetProcess);
|
|
658
658
|
targetProcess.init();
|
|
659
659
|
targetProcess.run();
|
|
660
660
|
targetProcess.sendMessage(message);
|
|
@@ -692,7 +692,7 @@ proto._onCallActivity = function onCallActivity(routingKey, message) {
|
|
|
692
692
|
|
|
693
693
|
this._activateProcess(targetProcess);
|
|
694
694
|
|
|
695
|
-
this[
|
|
695
|
+
this[kProcesses].running.push(targetProcess);
|
|
696
696
|
targetProcess.init(bpExecutionId);
|
|
697
697
|
targetProcess.run({
|
|
698
698
|
inbound: [(0, _messageHelper.cloneContent)(content)]
|
|
@@ -746,7 +746,7 @@ proto._onDelegateMessage = function onDelegateMessage(routingKey, executeMessage
|
|
|
746
746
|
};
|
|
747
747
|
|
|
748
748
|
proto._removeProcessByExecutionId = function removeProcessByExecutionId(processExecutionId) {
|
|
749
|
-
const running = this[
|
|
749
|
+
const running = this[kProcesses].running;
|
|
750
750
|
const idx = running.findIndex(p => p.executionId === processExecutionId);
|
|
751
751
|
if (idx === -1) return;
|
|
752
752
|
return running.splice(idx, 1)[0];
|
|
@@ -755,14 +755,14 @@ proto._removeProcessByExecutionId = function removeProcessByExecutionId(processE
|
|
|
755
755
|
proto._complete = function complete(completionType, content, options) {
|
|
756
756
|
this._deactivate();
|
|
757
757
|
|
|
758
|
-
const stateMessage = this[
|
|
758
|
+
const stateMessage = this[kExecuteMessage];
|
|
759
759
|
|
|
760
760
|
this._debug(`definition execution ${completionType} in ${Date.now() - stateMessage.properties.timestamp}ms`);
|
|
761
761
|
|
|
762
762
|
if (!content) content = this._createMessage();
|
|
763
|
-
this[
|
|
764
|
-
|
|
765
|
-
this.broker.deleteQueue(this[
|
|
763
|
+
this[kCompleted] = true;
|
|
764
|
+
this[kStatus] = completionType;
|
|
765
|
+
this.broker.deleteQueue(this[kProcessesQ].name);
|
|
766
766
|
return this.broker.publish('execution', `execution.${completionType}.${this.executionId}`, { ...stateMessage.content,
|
|
767
767
|
output: { ...this.environment.output
|
|
768
768
|
},
|
|
@@ -775,23 +775,12 @@ proto._complete = function complete(completionType, content, options) {
|
|
|
775
775
|
});
|
|
776
776
|
};
|
|
777
777
|
|
|
778
|
-
proto.publishCompletionMessage = function publishCompletionMessage(completionType, content) {
|
|
779
|
-
this._deactivate();
|
|
780
|
-
|
|
781
|
-
this._debug(completionType);
|
|
782
|
-
|
|
783
|
-
if (!content) content = this._createMessage();
|
|
784
|
-
return this.broker.publish('execution', `execution.${completionType}.${this.executionId}`, content, {
|
|
785
|
-
type: completionType
|
|
786
|
-
});
|
|
787
|
-
};
|
|
788
|
-
|
|
789
778
|
proto._createMessage = function createMessage(content = {}) {
|
|
790
779
|
return {
|
|
791
780
|
id: this.id,
|
|
792
781
|
type: this.type,
|
|
793
782
|
executionId: this.executionId,
|
|
794
|
-
status: this
|
|
783
|
+
status: this[kStatus],
|
|
795
784
|
...content
|
|
796
785
|
};
|
|
797
786
|
};
|
|
@@ -820,5 +809,5 @@ proto._getProcessApiByExecutionId = function getProcessApiByExecutionId(parentEx
|
|
|
820
809
|
};
|
|
821
810
|
|
|
822
811
|
proto._debug = function debug(logMessage) {
|
|
823
|
-
this[
|
|
812
|
+
this[kParent].logger.debug(`<${this.executionId} (${this.id})> ${logMessage}`);
|
|
824
813
|
};
|
|
@@ -9,9 +9,9 @@ var _shared = require("../shared");
|
|
|
9
9
|
|
|
10
10
|
var _messageHelper = require("../messageHelper");
|
|
11
11
|
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
12
|
+
const kMessageQ = Symbol.for('cancelQ');
|
|
13
|
+
const kCompleted = Symbol.for('completed');
|
|
14
|
+
const kExecuteMessage = Symbol.for('executeMessage');
|
|
15
15
|
|
|
16
16
|
function CancelEventDefinition(activity, eventDefinition) {
|
|
17
17
|
const {
|
|
@@ -33,9 +33,9 @@ function CancelEventDefinition(activity, eventDefinition) {
|
|
|
33
33
|
this.logger = environment.Logger(type.toLowerCase());
|
|
34
34
|
|
|
35
35
|
if (!isThrowing) {
|
|
36
|
-
this[
|
|
36
|
+
this[kCompleted] = false;
|
|
37
37
|
const messageQueueName = `${reference.referenceType}-${(0, _shared.brokerSafeId)(id)}-q`;
|
|
38
|
-
this[
|
|
38
|
+
this[kMessageQ] = broker.assertQueue(messageQueueName, {
|
|
39
39
|
autoDelete: false,
|
|
40
40
|
durable: true
|
|
41
41
|
});
|
|
@@ -49,7 +49,7 @@ function CancelEventDefinition(activity, eventDefinition) {
|
|
|
49
49
|
const proto = CancelEventDefinition.prototype;
|
|
50
50
|
Object.defineProperty(proto, 'executionId', {
|
|
51
51
|
get() {
|
|
52
|
-
const message = this[
|
|
52
|
+
const message = this[kExecuteMessage];
|
|
53
53
|
return message && message.content.executionId;
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -60,8 +60,8 @@ proto.execute = function execute(executeMessage) {
|
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
proto.executeCatch = function executeCatch(executeMessage) {
|
|
63
|
-
this[
|
|
64
|
-
this[
|
|
63
|
+
this[kExecuteMessage] = executeMessage;
|
|
64
|
+
this[kCompleted] = false;
|
|
65
65
|
const executeContent = executeMessage.content;
|
|
66
66
|
const {
|
|
67
67
|
executionId,
|
|
@@ -72,11 +72,11 @@ proto.executeCatch = function executeCatch(executeMessage) {
|
|
|
72
72
|
|
|
73
73
|
const onCatchMessage = this._onCatchMessage.bind(this);
|
|
74
74
|
|
|
75
|
-
this[
|
|
75
|
+
this[kMessageQ].consume(onCatchMessage, {
|
|
76
76
|
noAck: true,
|
|
77
77
|
consumerTag: `_oncancel-${executionId}`
|
|
78
78
|
});
|
|
79
|
-
if (this[
|
|
79
|
+
if (this[kCompleted]) return;
|
|
80
80
|
|
|
81
81
|
const onApiMessage = this._onApiMessage.bind(this);
|
|
82
82
|
|
|
@@ -137,7 +137,7 @@ proto._onCatchMessage = function onCatchMessage(_, message) {
|
|
|
137
137
|
proto._onCancelTransaction = function onCancelTransaction(_, message) {
|
|
138
138
|
const broker = this.broker,
|
|
139
139
|
executionId = this.executionId;
|
|
140
|
-
const executeContent = this[
|
|
140
|
+
const executeContent = this[kExecuteMessage].content;
|
|
141
141
|
broker.cancel(`_oncancel-${executionId}`);
|
|
142
142
|
|
|
143
143
|
this._debug(`cancel transaction thrown by <${message.content.id}>`);
|
|
@@ -167,13 +167,13 @@ proto._onCancelTransaction = function onCancelTransaction(_, message) {
|
|
|
167
167
|
};
|
|
168
168
|
|
|
169
169
|
proto._complete = function complete(output) {
|
|
170
|
-
this[
|
|
170
|
+
this[kCompleted] = true;
|
|
171
171
|
|
|
172
172
|
this._stop();
|
|
173
173
|
|
|
174
174
|
this._debug('completed');
|
|
175
175
|
|
|
176
|
-
const content = (0, _messageHelper.cloneContent)(this[
|
|
176
|
+
const content = (0, _messageHelper.cloneContent)(this[kExecuteMessage].content, {
|
|
177
177
|
output,
|
|
178
178
|
state: 'cancel'
|
|
179
179
|
});
|
|
@@ -184,11 +184,11 @@ proto._onApiMessage = function onApiMessage(routingKey, message) {
|
|
|
184
184
|
switch (message.properties.type) {
|
|
185
185
|
case 'discard':
|
|
186
186
|
{
|
|
187
|
-
this[
|
|
187
|
+
this[kCompleted] = true;
|
|
188
188
|
|
|
189
189
|
this._stop();
|
|
190
190
|
|
|
191
|
-
const content = (0, _messageHelper.cloneContent)(this[
|
|
191
|
+
const content = (0, _messageHelper.cloneContent)(this[kExecuteMessage].content);
|
|
192
192
|
return this.broker.publish('execution', 'execute.discard', content);
|
|
193
193
|
}
|
|
194
194
|
|
|
@@ -209,7 +209,7 @@ proto._stop = function stop() {
|
|
|
209
209
|
broker.cancel(`_oncancel-${executionId}`);
|
|
210
210
|
broker.cancel(`_oncancelend-${executionId}`);
|
|
211
211
|
broker.cancel(`_onattached-cancel-${executionId}`);
|
|
212
|
-
this[
|
|
212
|
+
this[kMessageQ].purge();
|
|
213
213
|
};
|
|
214
214
|
|
|
215
215
|
proto._debug = function debug(msg) {
|