bpmn-elements 5.1.3 → 7.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 (119) hide show
  1. package/CHANGELOG.md +322 -0
  2. package/README.md +9 -3
  3. package/dist/index.js +71 -39
  4. package/dist/src/Api.js +77 -76
  5. package/dist/src/Context.js +169 -164
  6. package/dist/src/Environment.js +90 -102
  7. package/dist/src/EventBroker.js +89 -88
  8. package/dist/src/ExtensionsMapper.js +2 -2
  9. package/dist/src/MessageFormatter.js +164 -95
  10. package/dist/src/Scripts.js +6 -2
  11. package/dist/src/Timers.js +4 -6
  12. package/dist/src/activity/Activity.js +1108 -901
  13. package/dist/src/activity/ActivityExecution.js +342 -297
  14. package/dist/src/activity/Dummy.js +3 -3
  15. package/dist/src/definition/Definition.js +498 -444
  16. package/dist/src/definition/DefinitionExecution.js +722 -409
  17. package/dist/src/error/Errors.js +17 -7
  18. package/dist/src/eventDefinitions/CancelEventDefinition.js +190 -150
  19. package/dist/src/eventDefinitions/CompensateEventDefinition.js +194 -161
  20. package/dist/src/eventDefinitions/ConditionalEventDefinition.js +197 -135
  21. package/dist/src/eventDefinitions/ErrorEventDefinition.js +207 -165
  22. package/dist/src/eventDefinitions/EscalationEventDefinition.js +175 -141
  23. package/dist/src/eventDefinitions/EventDefinitionExecution.js +157 -129
  24. package/dist/src/eventDefinitions/LinkEventDefinition.js +174 -149
  25. package/dist/src/eventDefinitions/MessageEventDefinition.js +213 -176
  26. package/dist/src/eventDefinitions/SignalEventDefinition.js +203 -161
  27. package/dist/src/eventDefinitions/TerminateEventDefinition.js +21 -23
  28. package/dist/src/eventDefinitions/TimerEventDefinition.js +243 -228
  29. package/dist/src/events/BoundaryEvent.js +180 -144
  30. package/dist/src/events/EndEvent.js +18 -23
  31. package/dist/src/events/IntermediateCatchEvent.js +44 -58
  32. package/dist/src/events/IntermediateThrowEvent.js +18 -23
  33. package/dist/src/events/StartEvent.js +109 -94
  34. package/dist/src/flows/Association.js +94 -101
  35. package/dist/src/flows/MessageFlow.js +86 -103
  36. package/dist/src/flows/SequenceFlow.js +172 -184
  37. package/dist/src/gateways/EventBasedGateway.js +88 -84
  38. package/dist/src/gateways/ExclusiveGateway.js +13 -16
  39. package/dist/src/gateways/InclusiveGateway.js +11 -14
  40. package/dist/src/gateways/ParallelGateway.js +11 -14
  41. package/dist/src/getPropertyValue.js +34 -34
  42. package/dist/src/io/BpmnIO.js +31 -0
  43. package/dist/src/io/EnvironmentDataObject.js +33 -29
  44. package/dist/src/io/EnvironmentDataStore.js +52 -0
  45. package/dist/src/io/EnvironmentDataStoreReference.js +52 -0
  46. package/dist/src/io/InputOutputSpecification.js +177 -168
  47. package/dist/src/io/Properties.js +252 -0
  48. package/dist/src/messageHelper.js +1 -1
  49. package/dist/src/process/Process.js +433 -359
  50. package/dist/src/process/ProcessExecution.js +744 -645
  51. package/dist/src/shared.js +3 -6
  52. package/dist/src/tasks/CallActivity.js +160 -0
  53. package/dist/src/tasks/LoopCharacteristics.js +309 -330
  54. package/dist/src/tasks/ReceiveTask.js +233 -182
  55. package/dist/src/tasks/ScriptTask.js +35 -41
  56. package/dist/src/tasks/ServiceImplementation.js +13 -20
  57. package/dist/src/tasks/ServiceTask.js +82 -75
  58. package/dist/src/tasks/SignalTask.js +97 -93
  59. package/dist/src/tasks/StandardLoopCharacteristics.js +1 -1
  60. package/dist/src/tasks/SubProcess.js +195 -175
  61. package/dist/src/tasks/Task.js +17 -19
  62. package/index.js +8 -0
  63. package/package.json +16 -15
  64. package/src/Api.js +65 -59
  65. package/src/Context.js +142 -132
  66. package/src/Environment.js +88 -100
  67. package/src/EventBroker.js +67 -68
  68. package/src/ExtensionsMapper.js +2 -2
  69. package/src/MessageFormatter.js +132 -74
  70. package/src/Timers.js +4 -4
  71. package/src/activity/Activity.js +916 -757
  72. package/src/activity/ActivityExecution.js +293 -247
  73. package/src/activity/Dummy.js +2 -2
  74. package/src/definition/Definition.js +436 -401
  75. package/src/definition/DefinitionExecution.js +603 -343
  76. package/src/error/Errors.js +11 -6
  77. package/src/eventDefinitions/CancelEventDefinition.js +164 -121
  78. package/src/eventDefinitions/CompensateEventDefinition.js +158 -124
  79. package/src/eventDefinitions/ConditionalEventDefinition.js +147 -104
  80. package/src/eventDefinitions/ErrorEventDefinition.js +190 -131
  81. package/src/eventDefinitions/EscalationEventDefinition.js +139 -101
  82. package/src/eventDefinitions/EventDefinitionExecution.js +127 -95
  83. package/src/eventDefinitions/LinkEventDefinition.js +160 -129
  84. package/src/eventDefinitions/MessageEventDefinition.js +178 -121
  85. package/src/eventDefinitions/SignalEventDefinition.js +162 -106
  86. package/src/eventDefinitions/TerminateEventDefinition.js +19 -19
  87. package/src/eventDefinitions/TimerEventDefinition.js +202 -167
  88. package/src/events/BoundaryEvent.js +156 -115
  89. package/src/events/EndEvent.js +15 -18
  90. package/src/events/IntermediateCatchEvent.js +40 -44
  91. package/src/events/IntermediateThrowEvent.js +15 -18
  92. package/src/events/StartEvent.js +84 -50
  93. package/src/flows/Association.js +98 -113
  94. package/src/flows/MessageFlow.js +81 -97
  95. package/src/flows/SequenceFlow.js +145 -163
  96. package/src/gateways/EventBasedGateway.js +75 -68
  97. package/src/gateways/ExclusiveGateway.js +8 -13
  98. package/src/gateways/InclusiveGateway.js +8 -13
  99. package/src/gateways/ParallelGateway.js +8 -13
  100. package/src/getPropertyValue.js +34 -33
  101. package/src/io/BpmnIO.js +20 -0
  102. package/src/io/EnvironmentDataObject.js +29 -18
  103. package/src/io/EnvironmentDataStore.js +33 -0
  104. package/src/io/EnvironmentDataStoreReference.js +33 -0
  105. package/src/io/InputOutputSpecification.js +154 -157
  106. package/src/io/Properties.js +199 -0
  107. package/src/process/Process.js +374 -333
  108. package/src/process/ProcessExecution.js +606 -554
  109. package/src/shared.js +1 -5
  110. package/src/tasks/CallActivity.js +130 -0
  111. package/src/tasks/LoopCharacteristics.js +290 -289
  112. package/src/tasks/ReceiveTask.js +174 -107
  113. package/src/tasks/ScriptTask.js +27 -30
  114. package/src/tasks/ServiceImplementation.js +13 -18
  115. package/src/tasks/ServiceTask.js +67 -60
  116. package/src/tasks/SignalTask.js +77 -52
  117. package/src/tasks/StandardLoopCharacteristics.js +1 -1
  118. package/src/tasks/SubProcess.js +184 -157
  119. package/src/tasks/Task.js +15 -19
@@ -3,376 +3,421 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = ActivityExecution;
6
+ exports.default = void 0;
7
7
 
8
8
  var _Api = require("../Api");
9
9
 
10
10
  var _messageHelper = require("../messageHelper");
11
11
 
12
+ const completedSymbol = Symbol.for('completed');
13
+ const executeQSymbol = Symbol.for('executeQ');
14
+ const executeMessageSymbol = Symbol.for('executeMessage');
15
+ const messageHandlersSymbol = Symbol.for('messageHandlers');
16
+ const postponedSymbol = Symbol.for('postponed');
17
+ var _default = ActivityExecution;
18
+ exports.default = _default;
19
+
12
20
  function ActivityExecution(activity, context) {
13
- const {
14
- id,
15
- broker,
16
- logger,
17
- isSubProcess,
18
- Behaviour,
19
- environment
20
- } = activity;
21
- const {
22
- batchSize = 50
23
- } = environment.settings;
24
- const postponed = [];
25
- let source,
26
- initMessage,
27
- completed = false,
28
- executionId;
29
- const executeQ = broker.assertQueue('execute-q', {
21
+ this.activity = activity;
22
+ this.context = context;
23
+ this.id = activity.id;
24
+ this.broker = activity.broker;
25
+ this[postponedSymbol] = [];
26
+ this[completedSymbol] = false;
27
+ this[executeQSymbol] = this.broker.assertQueue('execute-q', {
30
28
  durable: true,
31
29
  autoDelete: false
32
30
  });
33
- const executionApi = {
34
- get completed() {
35
- return completed;
36
- },
37
-
38
- get source() {
39
- return source;
40
- },
41
-
42
- discard,
43
- execute,
44
- passthrough,
45
- getApi,
46
- getPostponed,
47
- getState,
48
- recover,
49
- stop
31
+ this[messageHandlersSymbol] = {
32
+ onParentApiMessage: this._onParentApiMessage.bind(this),
33
+ onExecuteMessage: this._onExecuteMessage.bind(this)
50
34
  };
51
- return executionApi;
35
+ }
52
36
 
53
- function getPostponed() {
54
- let apis = postponed.map(msg => getApi(msg));
55
- if (!isSubProcess || !source) return apis;
56
- apis = apis.concat(source.getPostponed());
57
- return apis;
37
+ const proto = ActivityExecution.prototype;
38
+ Object.defineProperty(proto, 'completed', {
39
+ enumerable: true,
40
+
41
+ get() {
42
+ return this[completedSymbol];
58
43
  }
59
44
 
60
- function execute(executeMessage) {
61
- if (!executeMessage) throw new Error('Execution requires message');
62
- if (!executeMessage.content || !executeMessage.content.executionId) throw new Error('Execution requires execution id');
63
- const isRedelivered = executeMessage.fields.redelivered;
64
- executionId = executeMessage.content.executionId;
65
- initMessage = (0, _messageHelper.cloneMessage)(executeMessage);
66
- initMessage.content = { ...initMessage.content,
67
- executionId,
68
- state: 'start',
69
- isRootScope: true
70
- };
71
-
72
- if (isRedelivered) {
73
- postponed.splice(0);
74
- logger.debug(`<${executionId} (${id})> resume execution`);
75
- if (!source) source = Behaviour(activity, context);
76
- activate();
77
- return broker.publish('execution', 'execute.resume.execution', (0, _messageHelper.cloneContent)(initMessage.content), {
78
- persistent: false
79
- });
80
- }
45
+ });
81
46
 
82
- logger.debug(`<${executionId} (${id})> execute`);
83
- activate();
84
- source = Behaviour(activity, context);
85
- broker.publish('execution', 'execute.start', (0, _messageHelper.cloneContent)(initMessage.content));
86
- }
47
+ proto.execute = function execute(executeMessage) {
48
+ if (!executeMessage) throw new Error('Execution requires message');
49
+ const executionId = executeMessage.content && executeMessage.content.executionId;
50
+ if (!executionId) throw new Error('Execution requires execution id');
51
+ this.executionId = executionId;
52
+ const initMessage = this[executeMessageSymbol] = (0, _messageHelper.cloneMessage)(executeMessage, {
53
+ executionId,
54
+ state: 'start',
55
+ isRootScope: true
56
+ });
87
57
 
88
- function passthrough(executeMessage) {
89
- if (!source) return execute(executeMessage);
90
- return source.execute(executeMessage);
91
- }
58
+ if (executeMessage.fields.redelivered) {
59
+ this[postponedSymbol].splice(0);
92
60
 
93
- function discard() {
94
- if (completed) return;
95
- if (!initMessage) return logger.warn(`<${id}> is not executing`);
96
- getApi(initMessage).discard();
97
- }
61
+ this._debug('resume execution');
98
62
 
99
- function stop() {
100
- if (!initMessage) return;
101
- getApi(initMessage).stop();
63
+ if (!this.source) this.source = new this.activity.Behaviour(this.activity, this.context);
64
+ this.activate();
65
+ return this.broker.publish('execution', 'execute.resume.execution', (0, _messageHelper.cloneContent)(initMessage.content), {
66
+ persistent: false
67
+ });
102
68
  }
103
69
 
104
- function getState() {
105
- const result = {
106
- completed
107
- };
108
- if (!source || !source.getState) return result;
109
- return { ...result,
110
- ...source.getState()
111
- };
70
+ this._debug('execute');
71
+
72
+ this.activate();
73
+ this.source = new this.activity.Behaviour(this.activity, this.context);
74
+ this.broker.publish('execution', 'execute.start', (0, _messageHelper.cloneContent)(initMessage.content));
75
+ };
76
+
77
+ proto.activate = function activate() {
78
+ if (this[completedSymbol]) return;
79
+ const broker = this.broker;
80
+ const batchSize = this.activity.environment.settings.batchSize || 50;
81
+ broker.bindQueue('execute-q', 'execution', 'execute.#', {
82
+ priority: 100
83
+ });
84
+ const {
85
+ onExecuteMessage,
86
+ onParentApiMessage
87
+ } = this[messageHandlersSymbol];
88
+ this[executeQSymbol].assertConsumer(onExecuteMessage, {
89
+ exclusive: true,
90
+ prefetch: batchSize * 2,
91
+ priority: 100,
92
+ consumerTag: '_activity-execute'
93
+ });
94
+ if (this[completedSymbol]) return this.deactivate();
95
+ broker.subscribeTmp('api', `activity.*.${this.executionId}`, onParentApiMessage, {
96
+ noAck: true,
97
+ consumerTag: '_activity-api-execution',
98
+ priority: 200
99
+ });
100
+ };
101
+
102
+ proto.deactivate = function deactivate() {
103
+ const broker = this.broker;
104
+ broker.cancel('_activity-api-execution');
105
+ broker.cancel('_activity-execute');
106
+ broker.unbindQueue('execute-q', 'execution', 'execute.#');
107
+ };
108
+
109
+ proto.discard = function discard() {
110
+ if (this[completedSymbol]) return;
111
+ const initMessage = this[executeMessageSymbol];
112
+ if (!initMessage) return this.activity.logger.warn(`<${this.id}> is not executing`);
113
+ this.getApi(initMessage).discard();
114
+ };
115
+
116
+ proto.getApi = function getApi(apiMessage) {
117
+ const self = this;
118
+ if (!apiMessage) apiMessage = this[executeMessageSymbol];
119
+
120
+ if (self.source.getApi) {
121
+ const sourceApi = self.source.getApi(apiMessage);
122
+ if (sourceApi) return sourceApi;
112
123
  }
113
124
 
114
- function recover(state) {
115
- postponed.splice(0);
116
- if (!state) return executionApi;
117
- if ('completed' in state) completed = state.completed;
118
- source = Behaviour(activity, context);
125
+ const api = (0, _Api.ActivityApi)(self.broker, apiMessage);
119
126
 
120
- if (source.recover) {
121
- source.recover(state);
122
- }
127
+ api.getExecuting = function getExecuting() {
128
+ return self[postponedSymbol].reduce((result, msg) => {
129
+ if (msg.content.executionId === apiMessage.content.executionId) return result;
130
+ result.push(self.getApi(msg));
131
+ return result;
132
+ }, []);
133
+ };
123
134
 
124
- return executionApi;
125
- }
135
+ return api;
136
+ };
126
137
 
127
- function activate() {
128
- if (completed) return;
129
- broker.bindQueue(executeQ.name, 'execution', 'execute.#', {
130
- priority: 100
131
- });
132
- executeQ.assertConsumer(onExecuteMessage, {
133
- exclusive: true,
134
- prefetch: batchSize * 2,
135
- priority: 100,
136
- consumerTag: '_activity-execute'
137
- });
138
- if (completed) return deactivate();
139
- broker.subscribeTmp('api', `activity.*.${executionId}`, onParentApiMessage, {
140
- noAck: true,
141
- consumerTag: '_activity-api-execution',
142
- priority: 200
143
- });
144
- }
138
+ proto.passthrough = function passthrough(executeMessage) {
139
+ if (!this.source) return this.execute(executeMessage);
140
+ return this._sourceExecute(executeMessage);
141
+ };
145
142
 
146
- function deactivate() {
147
- broker.cancel('_activity-api-execution');
148
- broker.cancel('_activity-execute');
149
- broker.unbindQueue(executeQ.name, 'execution', 'execute.#');
150
- }
143
+ proto.getPostponed = function getPostponed() {
144
+ let apis = this[postponedSymbol].map(msg => this.getApi(msg));
145
+ if (!this.activity.isSubProcess || !this.source) return apis;
146
+ apis = apis.concat(this.source.getPostponed());
147
+ return apis;
148
+ };
151
149
 
152
- function onParentApiMessage(routingKey, message) {
153
- const messageType = message.properties.type;
150
+ proto.getState = function getState() {
151
+ const result = {
152
+ completed: this[completedSymbol]
153
+ };
154
+ const source = this.source;
155
+ if (!source || !source.getState) return result;
156
+ return { ...result,
157
+ ...source.getState()
158
+ };
159
+ };
154
160
 
155
- switch (messageType) {
156
- case 'discard':
157
- executeQ.queueMessage({
158
- routingKey: 'execute.discard'
159
- }, (0, _messageHelper.cloneContent)(initMessage.content));
160
- break;
161
+ proto.recover = function recover(state) {
162
+ this[postponedSymbol].splice(0);
163
+ if (!state) return this;
164
+ if ('completed' in state) this[completedSymbol] = state.completed;
165
+ const source = this.source = new this.activity.Behaviour(this.activity, this.context);
161
166
 
162
- case 'stop':
163
- onStop(message);
164
- break;
165
- }
167
+ if (source.recover) {
168
+ source.recover(state);
166
169
  }
167
170
 
168
- function onStop(message) {
169
- const stoppedId = message && message.content && message.content.executionId;
170
- const running = getPostponed();
171
- running.forEach(api => {
172
- if (stoppedId !== api.content.executionId) {
173
- api.stop();
174
- }
175
- });
176
- broker.cancel('_activity-execute');
177
- broker.cancel('_activity-api-execution');
178
- }
171
+ return this;
172
+ };
173
+
174
+ proto.stop = function stop() {
175
+ const executeMessage = this[executeMessageSymbol];
176
+ if (!executeMessage) return;
177
+ this.getApi(executeMessage).stop();
178
+ };
179
179
 
180
- function onExecuteMessage(routingKey, message) {
181
- const {
182
- fields = {},
183
- content = {},
184
- properties = {}
185
- } = message;
186
- const isRedelivered = fields.redelivered;
187
- const {
188
- isRootScope,
189
- ignoreIfExecuting,
190
- keep,
191
- executionId: cexid,
180
+ proto._sourceExecute = function sourceExecute(executeMessage) {
181
+ try {
182
+ return this.source.execute(executeMessage);
183
+ } catch (error) {
184
+ return this.broker.publish('execution', 'execute.error', (0, _messageHelper.cloneContent)(executeMessage.content, {
192
185
  error
193
- } = content;
194
- const {
195
- persistent,
196
- correlationId
197
- } = properties;
198
- if (isRedelivered && persistent === false) return message.ack();
199
-
200
- switch (routingKey) {
201
- case 'execute.resume.execution':
202
- {
203
- if (!postponed.length) return broker.publish('execution', 'execute.start', (0, _messageHelper.cloneContent)(initMessage.content));
204
- break;
205
- }
186
+ }));
187
+ }
188
+ };
206
189
 
207
- case 'execute.error':
208
- case 'execute.discard':
209
- executionDiscard();
190
+ proto._onExecuteMessage = function onExecuteMessage(routingKey, message) {
191
+ const {
192
+ fields,
193
+ content,
194
+ properties
195
+ } = message;
196
+ const isRedelivered = fields.redelivered;
197
+ if (isRedelivered && properties.persistent === false) return message.ack();
198
+
199
+ switch (routingKey) {
200
+ case 'execute.resume.execution':
201
+ {
202
+ if (!this[postponedSymbol].length) return this.broker.publish('execution', 'execute.start', (0, _messageHelper.cloneContent)(this[executeMessageSymbol].content));
210
203
  break;
204
+ }
211
205
 
212
- case 'execute.cancel':
213
- case 'execute.completed':
214
- {
215
- if (isRedelivered) {
216
- message.ack();
217
- return broker.publish('execution', routingKey, getExecuteMessage().content);
218
- }
206
+ case 'execute.error':
207
+ case 'execute.discard':
208
+ return this._onExecutionDiscarded(message);
219
209
 
220
- executionCompleted();
221
- break;
210
+ case 'execute.cancel':
211
+ case 'execute.completed':
212
+ {
213
+ if (isRedelivered) {
214
+ message.ack();
215
+ return this.broker.publish('execution', routingKey, getExecuteMessage(message).content);
222
216
  }
223
217
 
224
- case 'execute.start':
225
- {
226
- if (!stateChangeMessage()) return;
227
- return source.execute(getExecuteMessage());
228
- }
218
+ return this._onExecutionCompleted(message);
219
+ }
229
220
 
230
- case 'execute.outbound.take':
231
- {
232
- if (isRedelivered) {
233
- message.ack();
234
- break;
235
- }
221
+ case 'execute.start':
222
+ {
223
+ if (!this._onStateChangeMessage(message)) return;
224
+ return this._sourceExecute(getExecuteMessage(message));
225
+ }
236
226
 
237
- broker.publish('execution', 'execution.outbound.take', (0, _messageHelper.cloneContent)(content), {
238
- type: 'outbound'
239
- });
227
+ case 'execute.outbound.take':
228
+ {
229
+ if (isRedelivered) {
230
+ message.ack();
240
231
  break;
241
232
  }
242
233
 
243
- default:
244
- {
245
- if (!stateChangeMessage()) return;
234
+ this.broker.publish('execution', 'execution.outbound.take', (0, _messageHelper.cloneContent)(content), {
235
+ type: 'outbound'
236
+ });
237
+ break;
238
+ }
239
+
240
+ default:
241
+ {
242
+ if (!this._onStateChangeMessage(message)) return;
246
243
 
247
- if (isRedelivered) {
248
- return source.execute(getExecuteMessage());
249
- }
244
+ if (isRedelivered) {
245
+ return this._sourceExecute(getExecuteMessage(message));
250
246
  }
247
+ }
248
+ }
249
+ };
250
+
251
+ proto._onStateChangeMessage = function onStateChangeMessage(message) {
252
+ const {
253
+ ignoreIfExecuting,
254
+ executionId
255
+ } = message.content;
256
+ const postponed = this[postponedSymbol];
257
+ const idx = postponed.findIndex(msg => msg.content.executionId === executionId);
258
+ let previousMsg;
259
+
260
+ if (idx > -1) {
261
+ if (ignoreIfExecuting) {
262
+ message.ack();
263
+ return false;
251
264
  }
252
265
 
253
- function stateChangeMessage() {
254
- const idx = postponed.findIndex(msg => msg.content.executionId === cexid);
255
- let previousMsg;
266
+ previousMsg = postponed.splice(idx, 1, message)[0];
267
+ previousMsg.ack();
268
+ return true;
269
+ }
256
270
 
257
- if (idx > -1) {
258
- if (ignoreIfExecuting) {
259
- message.ack();
260
- return false;
261
- }
271
+ postponed.push(message);
272
+ return true;
273
+ };
262
274
 
263
- previousMsg = postponed.splice(idx, 1, message)[0];
264
- previousMsg.ack();
265
- return true;
266
- }
275
+ proto._onExecutionCompleted = function onExecutionCompleted(message) {
276
+ const postponedMsg = this._ackPostponed(message);
267
277
 
268
- postponed.push(message);
269
- return true;
270
- }
278
+ if (!postponedMsg) return;
279
+ const postponed = this[postponedSymbol];
280
+ const {
281
+ executionId,
282
+ keep,
283
+ isRootScope
284
+ } = message.content;
271
285
 
272
- function getExecuteMessage() {
273
- const result = (0, _messageHelper.cloneMessage)(message, { ...(isRedelivered ? {
274
- isRecovered: true
275
- } : undefined)
276
- });
277
- result.content.ignoreIfExecuting = undefined;
278
- return result;
286
+ if (!isRootScope) {
287
+ this._debug('completed sub execution');
288
+
289
+ if (!keep) message.ack();
290
+
291
+ if (postponed.length === 1 && postponed[0].content.isRootScope && !postponed[0].content.preventComplete) {
292
+ return this.broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(postponed[0].content));
279
293
  }
280
294
 
281
- function executionCompleted() {
282
- const postponedMsg = ackPostponed(message);
283
- if (!postponedMsg) return;
295
+ return;
296
+ }
284
297
 
285
- if (!isRootScope) {
286
- logger.debug(`<${cexid} (${id})> completed sub execution`);
287
- if (!keep) message.ack();
298
+ this._debug('completed execution', executionId);
288
299
 
289
- if (postponed.length === 1 && postponed[0].content.isRootScope && !postponed[0].content.preventComplete) {
290
- return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(postponed[0].content));
291
- }
300
+ this[completedSymbol] = true;
301
+ message.ack(true);
302
+ this.deactivate();
303
+ const subApis = this.getPostponed();
304
+ postponed.splice(0);
292
305
 
293
- return;
294
- }
306
+ for (const api of subApis) api.discard();
295
307
 
296
- logger.debug(`<${cexid} (${id})> completed execution`);
297
- completed = true;
298
- message.ack(true);
299
- deactivate();
300
- const subApis = getPostponed();
301
- postponed.splice(0);
302
- subApis.forEach(api => api.discard());
303
- publishExecutionCompleted('completed', { ...postponedMsg.content,
304
- ...message.content
308
+ this._publishExecutionCompleted('completed', { ...postponedMsg.content,
309
+ ...message.content
310
+ }, message.properties.correlationId);
311
+ };
312
+
313
+ proto._onExecutionDiscarded = function onExecutionDiscarded(message) {
314
+ const postponedMsg = this._ackPostponed(message);
315
+
316
+ const {
317
+ isRootScope,
318
+ error
319
+ } = message.content;
320
+ if (!isRootScope && !postponedMsg) return;
321
+ const postponed = this[postponedSymbol];
322
+ const correlationId = message.properties.correlationId;
323
+
324
+ if (!error && !isRootScope) {
325
+ message.ack();
326
+
327
+ if (postponed.length === 1 && postponed[0].content.isRootScope) {
328
+ return this.broker.publish('execution', 'execute.discard', postponed[0].content, {
329
+ correlationId
305
330
  });
306
331
  }
307
332
 
308
- function executionDiscard() {
309
- const postponedMsg = ackPostponed(message);
310
- if (!isRootScope && !postponedMsg) return;
333
+ return;
334
+ }
311
335
 
312
- if (!error && !isRootScope) {
313
- message.ack();
336
+ message.ack(true);
337
+ this.deactivate();
338
+ const subApis = this.getPostponed();
339
+ postponed.splice(0);
314
340
 
315
- if (postponed.length === 1 && postponed[0].content.isRootScope) {
316
- return broker.publish('execution', 'execute.discard', { ...postponed[0].content
317
- }, {
318
- correlationId
319
- });
320
- }
341
+ for (const api of subApis) api.discard();
321
342
 
322
- return;
323
- }
343
+ if (error) {
344
+ return this._publishExecutionCompleted('error', (0, _messageHelper.cloneContent)(message.content, {
345
+ error
346
+ }), correlationId);
347
+ }
324
348
 
325
- message.ack(true);
326
- deactivate();
327
- const subApis = getPostponed();
328
- postponed.splice(0);
329
- subApis.forEach(api => api.discard());
330
- publishExecutionCompleted(error ? 'error' : 'discard', { ...content
331
- });
332
- }
349
+ this._publishExecutionCompleted('discard', message.content, correlationId);
350
+ };
333
351
 
334
- function publishExecutionCompleted(completionType, completeContent) {
335
- completed = true;
336
- broker.publish('execution', `execution.${completionType}`, { ...completeContent,
337
- state: completionType
352
+ proto._publishExecutionCompleted = function publishExecutionCompleted(completionType, completeContent, correlationId) {
353
+ this[completedSymbol] = true;
354
+ this.broker.publish('execution', `execution.${completionType}`, { ...completeContent,
355
+ state: completionType
356
+ }, {
357
+ type: completionType,
358
+ correlationId
359
+ });
360
+ };
361
+
362
+ proto._ackPostponed = function ackPostponed(completeMessage) {
363
+ const {
364
+ executionId: eid
365
+ } = completeMessage.content;
366
+ const postponed = this[postponedSymbol];
367
+ const idx = postponed.findIndex(({
368
+ content: c
369
+ }) => c.executionId === eid);
370
+ if (idx === -1) return;
371
+ const [msg] = postponed.splice(idx, 1);
372
+ msg.ack();
373
+ return msg;
374
+ };
375
+
376
+ proto._onParentApiMessage = function onParentApiMessage(routingKey, message) {
377
+ switch (message.properties.type) {
378
+ case 'error':
379
+ return this[executeQSymbol].queueMessage({
380
+ routingKey: 'execute.error'
338
381
  }, {
339
- type: completionType,
340
- correlationId
382
+ error: message.content.error
341
383
  });
342
- }
343
- }
344
384
 
345
- function ackPostponed(completeMessage) {
346
- const {
347
- executionId: eid
348
- } = completeMessage.content;
349
- const idx = postponed.findIndex(({
350
- content
351
- }) => content.executionId === eid);
352
- if (idx === -1) return;
353
- const [msg] = postponed.splice(idx, 1);
354
- msg.ack();
355
- return msg;
385
+ case 'discard':
386
+ return this[executeQSymbol].queueMessage({
387
+ routingKey: 'execute.discard'
388
+ }, (0, _messageHelper.cloneContent)(this[executeMessageSymbol].content));
389
+
390
+ case 'stop':
391
+ {
392
+ return this._onStop(message);
393
+ }
356
394
  }
395
+ };
357
396
 
358
- function getApi(apiMessage) {
359
- if (!apiMessage) apiMessage = initMessage;
397
+ proto._onStop = function onStop(message) {
398
+ const stoppedId = message && message.content && message.content.executionId;
399
+ const running = this.getPostponed();
360
400
 
361
- if (source.getApi) {
362
- const sourceApi = source.getApi(apiMessage);
363
- if (sourceApi) return sourceApi;
401
+ for (const api of running) {
402
+ if (stoppedId !== api.content.executionId) {
403
+ api.stop();
364
404
  }
405
+ }
365
406
 
366
- const api = (0, _Api.ActivityApi)(broker, apiMessage);
407
+ this.broker.cancel('_activity-execute');
408
+ this.broker.cancel('_activity-api-execution');
409
+ };
367
410
 
368
- api.getExecuting = function getExecuting() {
369
- return postponed.reduce((result, msg) => {
370
- if (msg.content.executionId === apiMessage.content.executionId) return result;
371
- result.push(getApi(msg));
372
- return result;
373
- }, []);
374
- };
411
+ proto._debug = function debug(logMessage, executionId) {
412
+ executionId = executionId || this.executionId;
413
+ this.activity.logger.debug(`<${executionId} (${this.id})> ${logMessage}`);
414
+ };
375
415
 
376
- return api;
377
- }
416
+ function getExecuteMessage(message) {
417
+ const result = (0, _messageHelper.cloneMessage)(message, { ...(message.fields.redelivered ? {
418
+ isRecovered: true
419
+ } : undefined),
420
+ ignoreIfExecuting: undefined
421
+ });
422
+ return result;
378
423
  }