bpmn-elements 7.0.0 → 8.1.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 +23 -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 +106 -106
- package/dist/src/activity/ActivityExecution.js +37 -37
- package/dist/src/activity/Message.js +2 -2
- package/dist/src/activity/Signal.js +2 -2
- 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 +76 -53
- package/dist/src/events/BoundaryEvent.js +67 -38
- 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 +15 -16
- 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 +99 -100
- package/src/activity/ActivityExecution.js +35 -35
- package/src/activity/Message.js +1 -1
- package/src/activity/Signal.js +1 -1
- 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 +61 -44
- package/src/events/BoundaryEvent.js +53 -36
- 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
|
@@ -3,45 +3,54 @@ import {DefinitionApi} from '../Api';
|
|
|
3
3
|
import {brokerSafeId} from '../shared';
|
|
4
4
|
import {cloneContent, cloneMessage, pushParent, cloneParent} from '../messageHelper';
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
6
|
+
const kActivated = Symbol.for('activated');
|
|
7
|
+
const kProcessesQ = Symbol.for('processesQ');
|
|
8
|
+
const kCompleted = Symbol.for('completed');
|
|
9
|
+
const kExecuteMessage = Symbol.for('executeMessage');
|
|
10
|
+
const kMessageHandlers = Symbol.for('messageHandlers');
|
|
11
|
+
const kParent = Symbol.for('definition');
|
|
12
|
+
const kProcesses = Symbol.for('processes');
|
|
13
|
+
const kStatus = Symbol.for('status');
|
|
14
|
+
const kStopped = Symbol.for('stopped');
|
|
15
15
|
|
|
16
16
|
export default function DefinitionExecution(definition, context) {
|
|
17
17
|
const broker = definition.broker;
|
|
18
18
|
|
|
19
|
-
this[
|
|
19
|
+
this[kParent] = definition;
|
|
20
20
|
this.id = definition.id;
|
|
21
21
|
this.type = definition.type;
|
|
22
22
|
this.broker = broker;
|
|
23
|
-
this.environment = definition.environment;
|
|
23
|
+
const environment = this.environment = definition.environment;
|
|
24
24
|
this.context = context;
|
|
25
25
|
|
|
26
|
-
const processes =
|
|
27
|
-
|
|
26
|
+
const processes = context.getProcesses();
|
|
27
|
+
const ids = [];
|
|
28
|
+
const executable = [];
|
|
29
|
+
for (const bp of processes) {
|
|
30
|
+
bp.environment.assignVariables(environment.variables);
|
|
31
|
+
bp.environment.assignSettings(environment.settings);
|
|
32
|
+
ids.push(bp.id);
|
|
33
|
+
if (bp.isExecutable) executable.push(bp);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
this[kProcesses] = {
|
|
28
37
|
processes,
|
|
29
38
|
running: [],
|
|
30
|
-
ids
|
|
31
|
-
executable
|
|
39
|
+
ids,
|
|
40
|
+
executable,
|
|
32
41
|
postponed: [],
|
|
33
42
|
};
|
|
34
43
|
|
|
35
44
|
broker.assertExchange('execution', 'topic', {autoDelete: false, durable: true});
|
|
36
|
-
broker.assertQueue('activity-q', {autoDelete: false, durable: false});
|
|
37
45
|
|
|
38
|
-
this[completedSymbol] = false;
|
|
39
|
-
this[stoppedSymbol] = false;
|
|
40
|
-
this[activatedSymbol] = false;
|
|
41
|
-
this[statusSymbol] = 'init';
|
|
42
46
|
this.executionId = undefined;
|
|
47
|
+
this[kCompleted] = false;
|
|
48
|
+
this[kStopped] = false;
|
|
49
|
+
this[kActivated] = false;
|
|
50
|
+
this[kStatus] = 'init';
|
|
51
|
+
this[kProcessesQ] = undefined;
|
|
43
52
|
|
|
44
|
-
this[
|
|
53
|
+
this[kMessageHandlers] = {
|
|
45
54
|
onApiMessage: this._onApiMessage.bind(this),
|
|
46
55
|
onCallActivity: this._onCallActivity.bind(this),
|
|
47
56
|
onCancelCallActivity: this._onCancelCallActivity.bind(this),
|
|
@@ -57,40 +66,40 @@ const proto = DefinitionExecution.prototype;
|
|
|
57
66
|
Object.defineProperty(proto, 'stopped', {
|
|
58
67
|
enumerable: true,
|
|
59
68
|
get() {
|
|
60
|
-
return this[
|
|
69
|
+
return this[kStopped];
|
|
61
70
|
},
|
|
62
71
|
});
|
|
63
72
|
|
|
64
73
|
Object.defineProperty(proto, 'completed', {
|
|
65
74
|
enumerable: true,
|
|
66
75
|
get() {
|
|
67
|
-
return this[
|
|
76
|
+
return this[kCompleted];
|
|
68
77
|
},
|
|
69
78
|
});
|
|
70
79
|
|
|
71
80
|
Object.defineProperty(proto, 'status', {
|
|
72
81
|
enumerable: true,
|
|
73
82
|
get() {
|
|
74
|
-
return this[
|
|
83
|
+
return this[kStatus];
|
|
75
84
|
},
|
|
76
85
|
});
|
|
77
86
|
|
|
78
87
|
Object.defineProperty(proto, 'processes', {
|
|
79
88
|
enumerable: true,
|
|
80
89
|
get() {
|
|
81
|
-
return this[
|
|
90
|
+
return this[kProcesses].running;
|
|
82
91
|
},
|
|
83
92
|
});
|
|
84
93
|
|
|
85
94
|
Object.defineProperty(proto, 'postponedCount', {
|
|
86
95
|
get() {
|
|
87
|
-
return this[
|
|
96
|
+
return this[kProcesses].postponed.length;
|
|
88
97
|
},
|
|
89
98
|
});
|
|
90
99
|
|
|
91
100
|
Object.defineProperty(proto, 'isRunning', {
|
|
92
101
|
get() {
|
|
93
|
-
return this[
|
|
102
|
+
return this[kActivated];
|
|
94
103
|
},
|
|
95
104
|
});
|
|
96
105
|
|
|
@@ -100,21 +109,20 @@ proto.execute = function execute(executeMessage) {
|
|
|
100
109
|
const executionId = this.executionId = content.executionId;
|
|
101
110
|
if (!executionId) throw new Error('Definition execution requires execution id');
|
|
102
111
|
|
|
103
|
-
|
|
104
|
-
this[executeMessageSymbol] = cloneMessage(executeMessage, {
|
|
112
|
+
this[kExecuteMessage] = cloneMessage(executeMessage, {
|
|
105
113
|
executionId,
|
|
106
114
|
state: 'start',
|
|
107
115
|
});
|
|
108
116
|
|
|
109
|
-
this[
|
|
117
|
+
this[kStopped] = false;
|
|
110
118
|
|
|
111
|
-
this[
|
|
119
|
+
this[kProcessesQ] = this.broker.assertQueue(`execute-${executionId}-q`, {durable: true, autoDelete: false});
|
|
112
120
|
|
|
113
121
|
if (executeMessage.fields.redelivered) {
|
|
114
122
|
return this.resume();
|
|
115
123
|
}
|
|
116
124
|
|
|
117
|
-
const {running, executable} = this[
|
|
125
|
+
const {running, executable} = this[kProcesses];
|
|
118
126
|
|
|
119
127
|
if (content.processId) {
|
|
120
128
|
const startWithProcess = this.getProcessById(content.processId);
|
|
@@ -132,27 +140,19 @@ proto.execute = function execute(executeMessage) {
|
|
|
132
140
|
};
|
|
133
141
|
|
|
134
142
|
proto.resume = function resume() {
|
|
135
|
-
this._debug(`resume ${this
|
|
143
|
+
this._debug(`resume ${this[kStatus]} definition execution`);
|
|
136
144
|
|
|
137
|
-
if (this
|
|
145
|
+
if (this[kCompleted]) return this._complete('completed');
|
|
138
146
|
|
|
139
|
-
const {running, postponed} = this[
|
|
147
|
+
const {running, postponed} = this[kProcesses];
|
|
140
148
|
this._activate(running);
|
|
141
149
|
postponed.splice(0);
|
|
142
|
-
this[
|
|
150
|
+
this[kProcessesQ].consume(this[kMessageHandlers].onProcessMessage, {
|
|
143
151
|
prefetch: 1000,
|
|
144
152
|
consumerTag: `_definition-activity-${this.executionId}`,
|
|
145
153
|
});
|
|
146
154
|
|
|
147
|
-
if (this
|
|
148
|
-
switch (this.status) {
|
|
149
|
-
case 'init':
|
|
150
|
-
return this._start();
|
|
151
|
-
case 'executing': {
|
|
152
|
-
if (!this.postponedCount) return this._complete('completed');
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
155
|
+
if (this[kCompleted]) return;
|
|
156
156
|
|
|
157
157
|
for (const bp of running) bp.resume();
|
|
158
158
|
};
|
|
@@ -161,21 +161,30 @@ proto.recover = function recover(state) {
|
|
|
161
161
|
if (!state) return this;
|
|
162
162
|
this.executionId = state.executionId;
|
|
163
163
|
|
|
164
|
-
this[
|
|
165
|
-
this[
|
|
166
|
-
this[
|
|
164
|
+
this[kStopped] = state.stopped;
|
|
165
|
+
this[kCompleted] = state.completed;
|
|
166
|
+
this[kStatus] = state.status;
|
|
167
167
|
|
|
168
|
-
this._debug(`recover ${this
|
|
168
|
+
this._debug(`recover ${this[kStatus]} definition execution`);
|
|
169
169
|
|
|
170
|
-
const running = this[
|
|
170
|
+
const running = this[kProcesses].running;
|
|
171
171
|
running.splice(0);
|
|
172
172
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
173
|
+
const ids = [];
|
|
174
|
+
for (const bpState of state.processes) {
|
|
175
|
+
const bpid = bpState.id;
|
|
176
|
+
let bp;
|
|
177
|
+
if (ids.indexOf(bpid) > -1) {
|
|
178
|
+
bp = this.context.getNewProcessById(bpid);
|
|
179
|
+
} else {
|
|
180
|
+
bp = this.getProcessById(bpid);
|
|
181
|
+
}
|
|
182
|
+
if (!bp) return;
|
|
183
|
+
|
|
184
|
+
ids.push(bpid);
|
|
185
|
+
bp.recover(bpState);
|
|
186
|
+
running.push(bp);
|
|
187
|
+
}
|
|
179
188
|
|
|
180
189
|
return this;
|
|
181
190
|
};
|
|
@@ -185,7 +194,7 @@ proto.stop = function stop() {
|
|
|
185
194
|
};
|
|
186
195
|
|
|
187
196
|
proto.getProcesses = function getProcesses() {
|
|
188
|
-
const {running, processes} = this[
|
|
197
|
+
const {running, processes} = this[kProcesses];
|
|
189
198
|
const result = running.slice();
|
|
190
199
|
for (const bp of processes) {
|
|
191
200
|
if (!result.find((runningBp) => bp.id === runningBp.id)) result.push(bp);
|
|
@@ -202,31 +211,31 @@ proto.getProcessesById = function getProcessesById(processId) {
|
|
|
202
211
|
};
|
|
203
212
|
|
|
204
213
|
proto.getProcessByExecutionId = function getProcessByExecutionId(processExecutionId) {
|
|
205
|
-
const running = this[
|
|
214
|
+
const running = this[kProcesses].running;
|
|
206
215
|
return running.find((bp) => bp.executionId === processExecutionId);
|
|
207
216
|
};
|
|
208
217
|
|
|
209
218
|
proto.getRunningProcesses = function getRunningProcesses() {
|
|
210
|
-
const running = this[
|
|
219
|
+
const running = this[kProcesses].running;
|
|
211
220
|
return running.filter((bp) => bp.executionId);
|
|
212
221
|
};
|
|
213
222
|
|
|
214
223
|
proto.getExecutableProcesses = function getExecutableProcesses() {
|
|
215
|
-
return this[
|
|
224
|
+
return this[kProcesses].executable.slice();
|
|
216
225
|
};
|
|
217
226
|
|
|
218
227
|
proto.getState = function getState() {
|
|
219
228
|
return {
|
|
220
229
|
executionId: this.executionId,
|
|
221
|
-
stopped: this
|
|
222
|
-
completed: this
|
|
223
|
-
status: this
|
|
224
|
-
processes: this[
|
|
230
|
+
stopped: this[kStopped],
|
|
231
|
+
completed: this[kCompleted],
|
|
232
|
+
status: this[kStatus],
|
|
233
|
+
processes: this[kProcesses].running.map((bp) => bp.getState()),
|
|
225
234
|
};
|
|
226
235
|
};
|
|
227
236
|
|
|
228
237
|
proto.getApi = function getApi(apiMessage) {
|
|
229
|
-
if (!apiMessage) apiMessage = this[
|
|
238
|
+
if (!apiMessage) apiMessage = this[kExecuteMessage] || {content: this._createMessage()};
|
|
230
239
|
|
|
231
240
|
const content = apiMessage.content;
|
|
232
241
|
if (content.executionId !== this.executionId) {
|
|
@@ -234,7 +243,7 @@ proto.getApi = function getApi(apiMessage) {
|
|
|
234
243
|
}
|
|
235
244
|
|
|
236
245
|
const api = DefinitionApi(this.broker, apiMessage);
|
|
237
|
-
const postponed = this[
|
|
246
|
+
const postponed = this[kProcesses].postponed;
|
|
238
247
|
const self = this;
|
|
239
248
|
|
|
240
249
|
api.getExecuting = function getExecuting() {
|
|
@@ -249,7 +258,7 @@ proto.getApi = function getApi(apiMessage) {
|
|
|
249
258
|
};
|
|
250
259
|
|
|
251
260
|
proto.getPostponed = function getPostponed(...args) {
|
|
252
|
-
const running = this[
|
|
261
|
+
const running = this[kProcesses].running;
|
|
253
262
|
return running.reduce((result, p) => {
|
|
254
263
|
result = result.concat(p.getPostponed(...args));
|
|
255
264
|
return result;
|
|
@@ -257,37 +266,38 @@ proto.getPostponed = function getPostponed(...args) {
|
|
|
257
266
|
};
|
|
258
267
|
|
|
259
268
|
proto._start = function start() {
|
|
260
|
-
const {ids, executable, postponed} = this[
|
|
269
|
+
const {ids, executable, postponed} = this[kProcesses];
|
|
261
270
|
if (!ids.length) {
|
|
262
|
-
return this.
|
|
271
|
+
return this._complete('completed');
|
|
263
272
|
}
|
|
273
|
+
|
|
264
274
|
if (!executable.length) {
|
|
265
275
|
return this._complete('error', {error: new Error('No executable process')});
|
|
266
276
|
}
|
|
267
277
|
|
|
268
|
-
this[
|
|
278
|
+
this[kStatus] = 'start';
|
|
269
279
|
|
|
270
280
|
for (const bp of executable) bp.init();
|
|
271
281
|
for (const bp of executable) bp.run();
|
|
272
282
|
|
|
273
283
|
postponed.splice(0);
|
|
274
|
-
this[
|
|
284
|
+
this[kProcessesQ].assertConsumer(this[kMessageHandlers].onProcessMessage, {
|
|
275
285
|
prefetch: 1000,
|
|
276
286
|
consumerTag: `_definition-activity-${this.executionId}`,
|
|
277
287
|
});
|
|
278
288
|
};
|
|
279
289
|
|
|
280
290
|
proto._activate = function activate(processList) {
|
|
281
|
-
this.broker.subscribeTmp('api', '#', this[
|
|
291
|
+
this.broker.subscribeTmp('api', '#', this[kMessageHandlers].onApiMessage, {
|
|
282
292
|
noAck: true,
|
|
283
293
|
consumerTag: '_definition-api-consumer',
|
|
284
294
|
});
|
|
285
295
|
for (const bp of processList) this._activateProcess(bp);
|
|
286
|
-
this[
|
|
296
|
+
this[kActivated] = true;
|
|
287
297
|
};
|
|
288
298
|
|
|
289
299
|
proto._activateProcess = function activateProcess(bp) {
|
|
290
|
-
const handlers = this[
|
|
300
|
+
const handlers = this[kMessageHandlers];
|
|
291
301
|
|
|
292
302
|
bp.broker.subscribeTmp('message', 'message.outbound', handlers.onMessageOutbound, {
|
|
293
303
|
noAck: true,
|
|
@@ -325,7 +335,7 @@ proto._onChildEvent = function onChildEvent(routingKey, originalMessage) {
|
|
|
325
335
|
const content = message.content;
|
|
326
336
|
const parent = content.parent = content.parent || {};
|
|
327
337
|
|
|
328
|
-
const isDirectChild = this[
|
|
338
|
+
const isDirectChild = this[kProcesses].ids.indexOf(content.id) > -1;
|
|
329
339
|
if (isDirectChild) {
|
|
330
340
|
parent.executionId = this.executionId;
|
|
331
341
|
} else {
|
|
@@ -335,14 +345,14 @@ proto._onChildEvent = function onChildEvent(routingKey, originalMessage) {
|
|
|
335
345
|
this.broker.publish('event', routingKey, content, {...message.properties, mandatory: false});
|
|
336
346
|
if (!isDirectChild) return;
|
|
337
347
|
|
|
338
|
-
this[
|
|
348
|
+
this[kProcessesQ].queueMessage(message.fields, cloneContent(content), message.properties);
|
|
339
349
|
};
|
|
340
350
|
|
|
341
351
|
proto._deactivate = function deactivate() {
|
|
342
352
|
this.broker.cancel('_definition-api-consumer');
|
|
343
353
|
this.broker.cancel(`_definition-activity-${this.executionId}`);
|
|
344
|
-
for (const bp of this[
|
|
345
|
-
this[
|
|
354
|
+
for (const bp of this[kProcesses].running) this._deactivateProcess(bp);
|
|
355
|
+
this[kActivated] = false;
|
|
346
356
|
};
|
|
347
357
|
|
|
348
358
|
proto._deactivateProcess = function deactivateProcess(bp) {
|
|
@@ -357,17 +367,14 @@ proto._deactivateProcess = function deactivateProcess(bp) {
|
|
|
357
367
|
proto._onProcessMessage = function onProcessMessage(routingKey, message) {
|
|
358
368
|
const content = message.content;
|
|
359
369
|
const isRedelivered = message.fields.redelivered;
|
|
360
|
-
const {id: childId,
|
|
370
|
+
const {id: childId, inbound} = content;
|
|
361
371
|
|
|
362
372
|
if (isRedelivered && message.properties.persistent === false) return;
|
|
363
373
|
|
|
364
374
|
switch (routingKey) {
|
|
365
375
|
case 'execution.stop': {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
return this._onStopped(message);
|
|
369
|
-
}
|
|
370
|
-
break;
|
|
376
|
+
message.ack();
|
|
377
|
+
return this._onStopped(message);
|
|
371
378
|
}
|
|
372
379
|
case 'process.leave': {
|
|
373
380
|
return this._onProcessCompleted(message);
|
|
@@ -377,9 +384,8 @@ proto._onProcessMessage = function onProcessMessage(routingKey, message) {
|
|
|
377
384
|
this._stateChangeMessage(message, true);
|
|
378
385
|
|
|
379
386
|
switch (routingKey) {
|
|
380
|
-
case 'process.discard':
|
|
381
387
|
case 'process.enter':
|
|
382
|
-
this[
|
|
388
|
+
this[kStatus] = 'executing';
|
|
383
389
|
break;
|
|
384
390
|
case 'process.discarded': {
|
|
385
391
|
if (inbound && inbound.length) {
|
|
@@ -412,7 +418,7 @@ proto._onProcessMessage = function onProcessMessage(routingKey, message) {
|
|
|
412
418
|
error: content.error,
|
|
413
419
|
}, {mandatory: true, type: 'error'});
|
|
414
420
|
} else {
|
|
415
|
-
for (const bp of this[
|
|
421
|
+
for (const bp of this[kProcesses].running.slice()) {
|
|
416
422
|
if (bp.id !== childId) bp.stop();
|
|
417
423
|
}
|
|
418
424
|
|
|
@@ -425,7 +431,7 @@ proto._onProcessMessage = function onProcessMessage(routingKey, message) {
|
|
|
425
431
|
|
|
426
432
|
proto._stateChangeMessage = function stateChangeMessage(message, postponeMessage) {
|
|
427
433
|
let previousMsg;
|
|
428
|
-
const postponed = this[
|
|
434
|
+
const postponed = this[kProcesses].postponed;
|
|
429
435
|
const idx = postponed.findIndex((msg) => msg.content.executionId === message.content.executionId);
|
|
430
436
|
if (idx > -1) {
|
|
431
437
|
previousMsg = postponed.splice(idx, 1)[0];
|
|
@@ -454,15 +460,14 @@ proto._onProcessCompleted = function onProcessCompleted(message) {
|
|
|
454
460
|
};
|
|
455
461
|
|
|
456
462
|
proto._onStopped = function onStopped(message) {
|
|
457
|
-
const running = this[
|
|
463
|
+
const running = this[kProcesses].running;
|
|
458
464
|
this._debug(`stop definition execution (stop process executions ${running.length})`);
|
|
459
|
-
this[
|
|
460
|
-
this._deactivate();
|
|
461
|
-
|
|
465
|
+
this[kProcessesQ].close();
|
|
462
466
|
for (const bp of running.slice()) bp.stop();
|
|
467
|
+
this._deactivate();
|
|
463
468
|
|
|
464
|
-
this[
|
|
465
|
-
return this.broker.publish('execution', `execution.stopped.${this.executionId}`, cloneContent(this[
|
|
469
|
+
this[kStopped] = true;
|
|
470
|
+
return this.broker.publish('execution', `execution.stopped.${this.executionId}`, cloneContent(this[kExecuteMessage].content, {
|
|
466
471
|
...message.content,
|
|
467
472
|
}), {type: 'stopped', persistent: false});
|
|
468
473
|
};
|
|
@@ -477,7 +482,7 @@ proto._onApiMessage = function onApiMessage(routingKey, message) {
|
|
|
477
482
|
}
|
|
478
483
|
|
|
479
484
|
if (delegate) {
|
|
480
|
-
for (const bp of this[
|
|
485
|
+
for (const bp of this[kProcesses].running.slice()) {
|
|
481
486
|
bp.broker.publish('api', routingKey, cloneContent(message.content), message.properties);
|
|
482
487
|
}
|
|
483
488
|
}
|
|
@@ -485,12 +490,12 @@ proto._onApiMessage = function onApiMessage(routingKey, message) {
|
|
|
485
490
|
if (this.executionId !== message.content.executionId) return;
|
|
486
491
|
|
|
487
492
|
if (messageType === 'stop') {
|
|
488
|
-
this[
|
|
493
|
+
this[kProcessesQ].queueMessage({routingKey: 'execution.stop'}, cloneContent(message.content), {persistent: false});
|
|
489
494
|
}
|
|
490
495
|
};
|
|
491
496
|
|
|
492
497
|
proto._startProcessesByMessage = function startProcessesByMessage(reference) {
|
|
493
|
-
const {processes: bps, running} = this[
|
|
498
|
+
const {processes: bps, running} = this[kProcesses];
|
|
494
499
|
if (bps.length < 2) return;
|
|
495
500
|
|
|
496
501
|
for (const bp of bps) {
|
|
@@ -542,7 +547,7 @@ proto._onMessageOutbound = function onMessageOutbound(routingKey, message) {
|
|
|
542
547
|
targetProcess = targetProcess || this.context.getNewProcessById(target.processId);
|
|
543
548
|
|
|
544
549
|
this._activateProcess(targetProcess);
|
|
545
|
-
this[
|
|
550
|
+
this[kProcesses].running.push(targetProcess);
|
|
546
551
|
targetProcess.init();
|
|
547
552
|
targetProcess.run();
|
|
548
553
|
targetProcess.sendMessage(message);
|
|
@@ -574,7 +579,7 @@ proto._onCallActivity = function onCallActivity(routingKey, message) {
|
|
|
574
579
|
this._debug(`call from <${fromParent.id}.${fromId}> to <${calledElement}>`);
|
|
575
580
|
|
|
576
581
|
this._activateProcess(targetProcess);
|
|
577
|
-
this[
|
|
582
|
+
this[kProcesses].running.push(targetProcess);
|
|
578
583
|
targetProcess.init(bpExecutionId);
|
|
579
584
|
targetProcess.run({inbound: [cloneContent(content)]});
|
|
580
585
|
};
|
|
@@ -619,7 +624,7 @@ proto._onDelegateMessage = function onDelegateMessage(routingKey, executeMessage
|
|
|
619
624
|
};
|
|
620
625
|
|
|
621
626
|
proto._removeProcessByExecutionId = function removeProcessByExecutionId(processExecutionId) {
|
|
622
|
-
const running = this[
|
|
627
|
+
const running = this[kProcesses].running;
|
|
623
628
|
const idx = running.findIndex((p) => p.executionId === processExecutionId);
|
|
624
629
|
if (idx === -1) return;
|
|
625
630
|
return running.splice(idx, 1)[0];
|
|
@@ -627,12 +632,12 @@ proto._removeProcessByExecutionId = function removeProcessByExecutionId(processE
|
|
|
627
632
|
|
|
628
633
|
proto._complete = function complete(completionType, content, options) {
|
|
629
634
|
this._deactivate();
|
|
630
|
-
const stateMessage = this[
|
|
635
|
+
const stateMessage = this[kExecuteMessage];
|
|
631
636
|
this._debug(`definition execution ${completionType} in ${Date.now() - stateMessage.properties.timestamp}ms`);
|
|
632
637
|
if (!content) content = this._createMessage();
|
|
633
|
-
this[
|
|
634
|
-
|
|
635
|
-
this.broker.deleteQueue(this[
|
|
638
|
+
this[kCompleted] = true;
|
|
639
|
+
this[kStatus] = completionType;
|
|
640
|
+
this.broker.deleteQueue(this[kProcessesQ].name);
|
|
636
641
|
|
|
637
642
|
return this.broker.publish('execution', `execution.${completionType}.${this.executionId}`, {
|
|
638
643
|
...stateMessage.content,
|
|
@@ -642,19 +647,12 @@ proto._complete = function complete(completionType, content, options) {
|
|
|
642
647
|
}, {type: completionType, mandatory: completionType === 'error', ...options});
|
|
643
648
|
};
|
|
644
649
|
|
|
645
|
-
proto.publishCompletionMessage = function publishCompletionMessage(completionType, content) {
|
|
646
|
-
this._deactivate();
|
|
647
|
-
this._debug(completionType);
|
|
648
|
-
if (!content) content = this._createMessage();
|
|
649
|
-
return this.broker.publish('execution', `execution.${completionType}.${this.executionId}`, content, { type: completionType });
|
|
650
|
-
};
|
|
651
|
-
|
|
652
650
|
proto._createMessage = function createMessage(content = {}) {
|
|
653
651
|
return {
|
|
654
652
|
id: this.id,
|
|
655
653
|
type: this.type,
|
|
656
654
|
executionId: this.executionId,
|
|
657
|
-
status: this
|
|
655
|
+
status: this[kStatus],
|
|
658
656
|
...content,
|
|
659
657
|
};
|
|
660
658
|
};
|
|
@@ -684,5 +682,5 @@ proto._getProcessApiByExecutionId = function getProcessApiByExecutionId(parentEx
|
|
|
684
682
|
};
|
|
685
683
|
|
|
686
684
|
proto._debug = function debug(logMessage) {
|
|
687
|
-
this[
|
|
685
|
+
this[kParent].logger.debug(`<${this.executionId} (${this.id})> ${logMessage}`);
|
|
688
686
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {brokerSafeId} from '../shared';
|
|
2
2
|
import {cloneContent, shiftParent} from '../messageHelper';
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
4
|
+
const kMessageQ = Symbol.for('cancelQ');
|
|
5
|
+
const kCompleted = Symbol.for('completed');
|
|
6
|
+
const kExecuteMessage = Symbol.for('executeMessage');
|
|
7
7
|
|
|
8
8
|
export default function CancelEventDefinition(activity, eventDefinition) {
|
|
9
9
|
const {id, broker, environment, isThrowing} = activity;
|
|
@@ -19,9 +19,9 @@ export default function CancelEventDefinition(activity, eventDefinition) {
|
|
|
19
19
|
this.logger = environment.Logger(type.toLowerCase());
|
|
20
20
|
|
|
21
21
|
if (!isThrowing) {
|
|
22
|
-
this[
|
|
22
|
+
this[kCompleted] = false;
|
|
23
23
|
const messageQueueName = `${reference.referenceType}-${brokerSafeId(id)}-q`;
|
|
24
|
-
this[
|
|
24
|
+
this[kMessageQ] = broker.assertQueue(messageQueueName, {autoDelete: false, durable: true});
|
|
25
25
|
broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, {durable: true, priority: 400});
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -30,7 +30,7 @@ const proto = CancelEventDefinition.prototype;
|
|
|
30
30
|
|
|
31
31
|
Object.defineProperty(proto, 'executionId', {
|
|
32
32
|
get() {
|
|
33
|
-
const message = this[
|
|
33
|
+
const message = this[kExecuteMessage];
|
|
34
34
|
return message && message.content.executionId;
|
|
35
35
|
},
|
|
36
36
|
});
|
|
@@ -40,8 +40,8 @@ proto.execute = function execute(executeMessage) {
|
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
proto.executeCatch = function executeCatch(executeMessage) {
|
|
43
|
-
this[
|
|
44
|
-
this[
|
|
43
|
+
this[kExecuteMessage] = executeMessage;
|
|
44
|
+
this[kCompleted] = false;
|
|
45
45
|
|
|
46
46
|
const executeContent = executeMessage.content;
|
|
47
47
|
const {executionId, parent} = executeContent;
|
|
@@ -49,12 +49,12 @@ proto.executeCatch = function executeCatch(executeMessage) {
|
|
|
49
49
|
|
|
50
50
|
const broker = this.broker;
|
|
51
51
|
const onCatchMessage = this._onCatchMessage.bind(this);
|
|
52
|
-
this[
|
|
52
|
+
this[kMessageQ].consume(onCatchMessage, {
|
|
53
53
|
noAck: true,
|
|
54
54
|
consumerTag: `_oncancel-${executionId}`,
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
if (this[
|
|
57
|
+
if (this[kCompleted]) return;
|
|
58
58
|
|
|
59
59
|
const onApiMessage = this._onApiMessage.bind(this);
|
|
60
60
|
broker.subscribeTmp('api', `activity.#.${parentExecutionId}`, onApiMessage, {
|
|
@@ -109,7 +109,7 @@ proto._onCatchMessage = function onCatchMessage(_, message) {
|
|
|
109
109
|
|
|
110
110
|
proto._onCancelTransaction = function onCancelTransaction(_, message) {
|
|
111
111
|
const broker = this.broker, executionId = this.executionId;
|
|
112
|
-
const executeContent = this[
|
|
112
|
+
const executeContent = this[kExecuteMessage].content;
|
|
113
113
|
broker.cancel(`_oncancel-${executionId}`);
|
|
114
114
|
|
|
115
115
|
this._debug(`cancel transaction thrown by <${message.content.id}>`);
|
|
@@ -133,10 +133,10 @@ proto._onCancelTransaction = function onCancelTransaction(_, message) {
|
|
|
133
133
|
};
|
|
134
134
|
|
|
135
135
|
proto._complete = function complete(output) {
|
|
136
|
-
this[
|
|
136
|
+
this[kCompleted] = true;
|
|
137
137
|
this._stop();
|
|
138
138
|
this._debug('completed');
|
|
139
|
-
const content = cloneContent(this[
|
|
139
|
+
const content = cloneContent(this[kExecuteMessage].content, {
|
|
140
140
|
output,
|
|
141
141
|
state: 'cancel',
|
|
142
142
|
});
|
|
@@ -146,9 +146,9 @@ proto._complete = function complete(output) {
|
|
|
146
146
|
proto._onApiMessage = function onApiMessage(routingKey, message) {
|
|
147
147
|
switch (message.properties.type) {
|
|
148
148
|
case 'discard': {
|
|
149
|
-
this[
|
|
149
|
+
this[kCompleted] = true;
|
|
150
150
|
this._stop();
|
|
151
|
-
const content = cloneContent(this[
|
|
151
|
+
const content = cloneContent(this[kExecuteMessage].content);
|
|
152
152
|
return this.broker.publish('execution', 'execute.discard', content);
|
|
153
153
|
}
|
|
154
154
|
case 'stop': {
|
|
@@ -165,7 +165,7 @@ proto._stop = function stop() {
|
|
|
165
165
|
broker.cancel(`_oncancel-${executionId}`);
|
|
166
166
|
broker.cancel(`_oncancelend-${executionId}`);
|
|
167
167
|
broker.cancel(`_onattached-cancel-${executionId}`);
|
|
168
|
-
this[
|
|
168
|
+
this[kMessageQ].purge();
|
|
169
169
|
};
|
|
170
170
|
|
|
171
171
|
proto._debug = function debug(msg) {
|