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.
Files changed (68) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/src/Context.js +50 -40
  3. package/dist/src/Environment.js +39 -19
  4. package/dist/src/MessageFormatter.js +11 -11
  5. package/dist/src/activity/Activity.js +91 -91
  6. package/dist/src/activity/ActivityExecution.js +35 -35
  7. package/dist/src/definition/Definition.js +50 -50
  8. package/dist/src/definition/DefinitionExecution.js +114 -125
  9. package/dist/src/eventDefinitions/CancelEventDefinition.js +16 -16
  10. package/dist/src/eventDefinitions/CompensateEventDefinition.js +24 -24
  11. package/dist/src/eventDefinitions/ConditionalEventDefinition.js +8 -8
  12. package/dist/src/eventDefinitions/ErrorEventDefinition.js +26 -26
  13. package/dist/src/eventDefinitions/EscalationEventDefinition.js +20 -20
  14. package/dist/src/eventDefinitions/EventDefinitionExecution.js +14 -14
  15. package/dist/src/eventDefinitions/LinkEventDefinition.js +15 -15
  16. package/dist/src/eventDefinitions/MessageEventDefinition.js +23 -23
  17. package/dist/src/eventDefinitions/SignalEventDefinition.js +24 -24
  18. package/dist/src/eventDefinitions/TimerEventDefinition.js +21 -21
  19. package/dist/src/events/BoundaryEvent.js +20 -20
  20. package/dist/src/events/EndEvent.js +3 -3
  21. package/dist/src/events/IntermediateCatchEvent.js +3 -3
  22. package/dist/src/events/IntermediateThrowEvent.js +3 -3
  23. package/dist/src/events/StartEvent.js +9 -9
  24. package/dist/src/flows/Association.js +7 -7
  25. package/dist/src/flows/MessageFlow.js +9 -9
  26. package/dist/src/flows/SequenceFlow.js +7 -7
  27. package/dist/src/gateways/EventBasedGateway.js +11 -11
  28. package/dist/src/io/InputOutputSpecification.js +4 -4
  29. package/dist/src/io/Properties.js +9 -9
  30. package/dist/src/process/Process.js +64 -61
  31. package/dist/src/process/ProcessExecution.js +93 -90
  32. package/dist/src/tasks/ReceiveTask.js +16 -16
  33. package/dist/src/tasks/SubProcess.js +16 -18
  34. package/package.json +9 -9
  35. package/src/Context.js +48 -40
  36. package/src/Environment.js +48 -20
  37. package/src/EventBroker.js +1 -1
  38. package/src/MessageFormatter.js +11 -11
  39. package/src/activity/Activity.js +91 -91
  40. package/src/activity/ActivityExecution.js +34 -34
  41. package/src/definition/Definition.js +51 -50
  42. package/src/definition/DefinitionExecution.js +111 -113
  43. package/src/eventDefinitions/CancelEventDefinition.js +16 -16
  44. package/src/eventDefinitions/CompensateEventDefinition.js +25 -24
  45. package/src/eventDefinitions/ConditionalEventDefinition.js +8 -8
  46. package/src/eventDefinitions/ErrorEventDefinition.js +26 -26
  47. package/src/eventDefinitions/EscalationEventDefinition.js +20 -20
  48. package/src/eventDefinitions/EventDefinitionExecution.js +14 -14
  49. package/src/eventDefinitions/LinkEventDefinition.js +15 -15
  50. package/src/eventDefinitions/MessageEventDefinition.js +23 -23
  51. package/src/eventDefinitions/SignalEventDefinition.js +24 -24
  52. package/src/eventDefinitions/TimerEventDefinition.js +21 -21
  53. package/src/events/BoundaryEvent.js +20 -20
  54. package/src/events/EndEvent.js +3 -3
  55. package/src/events/IntermediateCatchEvent.js +3 -3
  56. package/src/events/IntermediateThrowEvent.js +3 -3
  57. package/src/events/StartEvent.js +9 -9
  58. package/src/flows/Association.js +7 -7
  59. package/src/flows/MessageFlow.js +9 -9
  60. package/src/flows/SequenceFlow.js +7 -7
  61. package/src/gateways/EventBasedGateway.js +11 -11
  62. package/src/io/BpmnIO.js +5 -1
  63. package/src/io/InputOutputSpecification.js +4 -4
  64. package/src/io/Properties.js +9 -9
  65. package/src/process/Process.js +62 -58
  66. package/src/process/ProcessExecution.js +86 -88
  67. package/src/tasks/ReceiveTask.js +16 -16
  68. 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 activatedSymbol = Symbol.for('activated');
7
- const processesQSymbol = Symbol.for('processesQ');
8
- const completedSymbol = Symbol.for('completed');
9
- const executeMessageSymbol = Symbol.for('executeMessage');
10
- const messageHandlersSymbol = Symbol.for('messageHandlers');
11
- const parentSymbol = Symbol.for('definition');
12
- const processesSymbol = Symbol.for('processes');
13
- const statusSymbol = Symbol.for('status');
14
- const stoppedSymbol = Symbol.for('stopped');
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[parentSymbol] = definition;
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 = this[processesSymbol] = context.getProcesses();
27
- this[processesSymbol] = {
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: processes.map(({id: childId}) => childId),
31
- executable: context.getExecutableProcesses(),
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[messageHandlersSymbol] = {
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[stoppedSymbol];
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[completedSymbol];
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[statusSymbol];
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[processesSymbol].running;
90
+ return this[kProcesses].running;
82
91
  },
83
92
  });
84
93
 
85
94
  Object.defineProperty(proto, 'postponedCount', {
86
95
  get() {
87
- return this[processesSymbol].postponed.length;
96
+ return this[kProcesses].postponed.length;
88
97
  },
89
98
  });
90
99
 
91
100
  Object.defineProperty(proto, 'isRunning', {
92
101
  get() {
93
- return this[activatedSymbol];
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[stoppedSymbol] = false;
117
+ this[kStopped] = false;
110
118
 
111
- this[processesQSymbol] = this.broker.assertQueue(`execute-${executionId}-q`, {durable: true, autoDelete: false});
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[processesSymbol];
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.status} definition execution`);
143
+ this._debug(`resume ${this[kStatus]} definition execution`);
136
144
 
137
- if (this.completed) return this._complete('completed');
145
+ if (this[kCompleted]) return this._complete('completed');
138
146
 
139
- const {running, postponed} = this[processesSymbol];
147
+ const {running, postponed} = this[kProcesses];
140
148
  this._activate(running);
141
149
  postponed.splice(0);
142
- this[processesQSymbol].consume(this[messageHandlersSymbol].onProcessMessage, {
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.completed) return this._complete('completed');
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[stoppedSymbol] = state.stopped;
165
- this[completedSymbol] = state.completed;
166
- this[statusSymbol] = state.status;
164
+ this[kStopped] = state.stopped;
165
+ this[kCompleted] = state.completed;
166
+ this[kStatus] = state.status;
167
167
 
168
- this._debug(`recover ${this.status} definition execution`);
168
+ this._debug(`recover ${this[kStatus]} definition execution`);
169
169
 
170
- const running = this[processesSymbol].running;
170
+ const running = this[kProcesses].running;
171
171
  running.splice(0);
172
172
 
173
- state.processes.map((processState) => {
174
- const instance = this.context.getNewProcessById(processState.id);
175
- if (!instance) return;
176
- instance.recover(processState);
177
- running.push(instance);
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[processesSymbol];
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[processesSymbol].running;
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[processesSymbol].running;
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[processesSymbol].executable.slice();
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.stopped,
222
- completed: this.completed,
223
- status: this.status,
224
- processes: this[processesSymbol].running.map((bp) => bp.getState()),
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[executeMessageSymbol] || {content: this._createMessage()};
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[processesSymbol].postponed;
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[processesSymbol].running;
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[processesSymbol];
269
+ const {ids, executable, postponed} = this[kProcesses];
261
270
  if (!ids.length) {
262
- return this.publishCompletionMessage('completed');
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[statusSymbol] = 'start';
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[processesQSymbol].assertConsumer(this[messageHandlersSymbol].onProcessMessage, {
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[messageHandlersSymbol].onApiMessage, {
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[activatedSymbol] = true;
296
+ this[kActivated] = true;
287
297
  };
288
298
 
289
299
  proto._activateProcess = function activateProcess(bp) {
290
- const handlers = this[messageHandlersSymbol];
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[processesSymbol].ids.indexOf(content.id) > -1;
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[processesQSymbol].queueMessage(message.fields, cloneContent(content), message.properties);
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[processesSymbol].running) this._deactivateProcess(bp);
345
- this[activatedSymbol] = false;
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, executionId: childExecutionId, inbound} = content;
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
- if (childExecutionId === this.executionId) {
367
- message.ack();
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[statusSymbol] = 'executing';
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[processesSymbol].running.slice()) {
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[processesSymbol].postponed;
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[processesSymbol].running;
463
+ const running = this[kProcesses].running;
458
464
  this._debug(`stop definition execution (stop process executions ${running.length})`);
459
- this[processesQSymbol].close();
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[stoppedSymbol] = true;
465
- return this.broker.publish('execution', `execution.stopped.${this.executionId}`, cloneContent(this[executeMessageSymbol].content, {
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[processesSymbol].running.slice()) {
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[processesQSymbol].queueMessage({routingKey: 'execution.stop'}, cloneContent(message.content), {persistent: false});
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[processesSymbol];
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[processesSymbol].running.push(targetProcess);
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[processesSymbol].running.push(targetProcess);
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[processesSymbol].running;
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[executeMessageSymbol];
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[completedSymbol] = true;
634
- if (this.status !== 'terminated') this[statusSymbol] = completionType;
635
- this.broker.deleteQueue(this[processesQSymbol].name);
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.status,
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[parentSymbol].logger.debug(`<${this.executionId} (${this.id})> ${logMessage}`);
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 messageQSymbol = Symbol.for('cancelQ');
5
- const completedSymbol = Symbol.for('completed');
6
- const executeMessageSymbol = Symbol.for('executeMessage');
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[completedSymbol] = false;
22
+ this[kCompleted] = false;
23
23
  const messageQueueName = `${reference.referenceType}-${brokerSafeId(id)}-q`;
24
- this[messageQSymbol] = broker.assertQueue(messageQueueName, {autoDelete: false, durable: true});
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[executeMessageSymbol];
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[executeMessageSymbol] = executeMessage;
44
- this[completedSymbol] = false;
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[messageQSymbol].consume(onCatchMessage, {
52
+ this[kMessageQ].consume(onCatchMessage, {
53
53
  noAck: true,
54
54
  consumerTag: `_oncancel-${executionId}`,
55
55
  });
56
56
 
57
- if (this[completedSymbol]) return;
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[executeMessageSymbol].content;
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[completedSymbol] = true;
136
+ this[kCompleted] = true;
137
137
  this._stop();
138
138
  this._debug('completed');
139
- const content = cloneContent(this[executeMessageSymbol].content, {
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[completedSymbol] = true;
149
+ this[kCompleted] = true;
150
150
  this._stop();
151
- const content = cloneContent(this[executeMessageSymbol].content);
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[messageQSymbol].purge();
168
+ this[kMessageQ].purge();
169
169
  };
170
170
 
171
171
  proto._debug = function debug(msg) {