bpmn-elements 6.0.1 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/CHANGELOG.md +341 -0
  2. package/README.md +3 -0
  3. package/dist/index.js +52 -44
  4. package/dist/src/Api.js +77 -76
  5. package/dist/src/Context.js +176 -172
  6. package/dist/src/Environment.js +110 -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/activity/Activity.js +1105 -916
  12. package/dist/src/activity/ActivityExecution.js +342 -297
  13. package/dist/src/activity/Dummy.js +3 -3
  14. package/dist/src/definition/Definition.js +498 -444
  15. package/dist/src/definition/DefinitionExecution.js +710 -408
  16. package/dist/src/error/Errors.js +17 -7
  17. package/dist/src/eventDefinitions/CancelEventDefinition.js +190 -150
  18. package/dist/src/eventDefinitions/CompensateEventDefinition.js +194 -161
  19. package/dist/src/eventDefinitions/ConditionalEventDefinition.js +197 -135
  20. package/dist/src/eventDefinitions/ErrorEventDefinition.js +207 -165
  21. package/dist/src/eventDefinitions/EscalationEventDefinition.js +175 -141
  22. package/dist/src/eventDefinitions/EventDefinitionExecution.js +157 -129
  23. package/dist/src/eventDefinitions/LinkEventDefinition.js +174 -149
  24. package/dist/src/eventDefinitions/MessageEventDefinition.js +213 -176
  25. package/dist/src/eventDefinitions/SignalEventDefinition.js +203 -161
  26. package/dist/src/eventDefinitions/TerminateEventDefinition.js +21 -23
  27. package/dist/src/eventDefinitions/TimerEventDefinition.js +243 -228
  28. package/dist/src/events/BoundaryEvent.js +180 -144
  29. package/dist/src/events/EndEvent.js +18 -23
  30. package/dist/src/events/IntermediateCatchEvent.js +44 -58
  31. package/dist/src/events/IntermediateThrowEvent.js +18 -23
  32. package/dist/src/events/StartEvent.js +109 -94
  33. package/dist/src/flows/Association.js +94 -100
  34. package/dist/src/flows/MessageFlow.js +86 -103
  35. package/dist/src/flows/SequenceFlow.js +173 -182
  36. package/dist/src/gateways/EventBasedGateway.js +88 -84
  37. package/dist/src/gateways/ExclusiveGateway.js +13 -16
  38. package/dist/src/gateways/InclusiveGateway.js +11 -14
  39. package/dist/src/gateways/ParallelGateway.js +11 -14
  40. package/dist/src/getPropertyValue.js +34 -34
  41. package/dist/src/io/BpmnIO.js +17 -14
  42. package/dist/src/io/EnvironmentDataObject.js +33 -29
  43. package/dist/src/io/EnvironmentDataStore.js +33 -29
  44. package/dist/src/io/EnvironmentDataStoreReference.js +35 -31
  45. package/dist/src/io/InputOutputSpecification.js +177 -168
  46. package/dist/src/io/Properties.js +117 -124
  47. package/dist/src/messageHelper.js +1 -1
  48. package/dist/src/process/Process.js +439 -362
  49. package/dist/src/process/ProcessExecution.js +748 -646
  50. package/dist/src/shared.js +2 -2
  51. package/dist/src/tasks/CallActivity.js +160 -0
  52. package/dist/src/tasks/LoopCharacteristics.js +309 -330
  53. package/dist/src/tasks/ReceiveTask.js +233 -182
  54. package/dist/src/tasks/ScriptTask.js +35 -41
  55. package/dist/src/tasks/ServiceImplementation.js +13 -20
  56. package/dist/src/tasks/ServiceTask.js +82 -75
  57. package/dist/src/tasks/SignalTask.js +97 -93
  58. package/dist/src/tasks/StandardLoopCharacteristics.js +1 -1
  59. package/dist/src/tasks/SubProcess.js +193 -175
  60. package/dist/src/tasks/Task.js +17 -19
  61. package/index.js +2 -0
  62. package/package.json +16 -16
  63. package/src/Api.js +65 -59
  64. package/src/Context.js +145 -140
  65. package/src/Environment.js +116 -100
  66. package/src/EventBroker.js +67 -68
  67. package/src/ExtensionsMapper.js +2 -2
  68. package/src/MessageFormatter.js +132 -74
  69. package/src/activity/Activity.js +914 -776
  70. package/src/activity/ActivityExecution.js +293 -247
  71. package/src/activity/Dummy.js +2 -2
  72. package/src/definition/Definition.js +437 -401
  73. package/src/definition/DefinitionExecution.js +598 -340
  74. package/src/error/Errors.js +11 -6
  75. package/src/eventDefinitions/CancelEventDefinition.js +164 -121
  76. package/src/eventDefinitions/CompensateEventDefinition.js +159 -124
  77. package/src/eventDefinitions/ConditionalEventDefinition.js +147 -104
  78. package/src/eventDefinitions/ErrorEventDefinition.js +190 -131
  79. package/src/eventDefinitions/EscalationEventDefinition.js +139 -101
  80. package/src/eventDefinitions/EventDefinitionExecution.js +127 -95
  81. package/src/eventDefinitions/LinkEventDefinition.js +160 -129
  82. package/src/eventDefinitions/MessageEventDefinition.js +178 -121
  83. package/src/eventDefinitions/SignalEventDefinition.js +162 -106
  84. package/src/eventDefinitions/TerminateEventDefinition.js +19 -19
  85. package/src/eventDefinitions/TimerEventDefinition.js +202 -167
  86. package/src/events/BoundaryEvent.js +156 -115
  87. package/src/events/EndEvent.js +15 -18
  88. package/src/events/IntermediateCatchEvent.js +40 -44
  89. package/src/events/IntermediateThrowEvent.js +15 -18
  90. package/src/events/StartEvent.js +84 -50
  91. package/src/flows/Association.js +98 -112
  92. package/src/flows/MessageFlow.js +81 -97
  93. package/src/flows/SequenceFlow.js +146 -160
  94. package/src/gateways/EventBasedGateway.js +75 -68
  95. package/src/gateways/ExclusiveGateway.js +8 -13
  96. package/src/gateways/InclusiveGateway.js +8 -13
  97. package/src/gateways/ParallelGateway.js +8 -13
  98. package/src/getPropertyValue.js +34 -33
  99. package/src/io/BpmnIO.js +20 -15
  100. package/src/io/EnvironmentDataObject.js +29 -18
  101. package/src/io/EnvironmentDataStore.js +29 -18
  102. package/src/io/EnvironmentDataStoreReference.js +31 -20
  103. package/src/io/InputOutputSpecification.js +154 -157
  104. package/src/io/Properties.js +95 -97
  105. package/src/process/Process.js +378 -333
  106. package/src/process/ProcessExecution.js +603 -553
  107. package/src/tasks/CallActivity.js +130 -0
  108. package/src/tasks/LoopCharacteristics.js +290 -289
  109. package/src/tasks/ReceiveTask.js +174 -107
  110. package/src/tasks/ScriptTask.js +27 -30
  111. package/src/tasks/ServiceImplementation.js +13 -18
  112. package/src/tasks/ServiceTask.js +67 -60
  113. package/src/tasks/SignalTask.js +77 -52
  114. package/src/tasks/StandardLoopCharacteristics.js +1 -1
  115. package/src/tasks/SubProcess.js +184 -157
  116. package/src/tasks/Task.js +15 -19
@@ -1,306 +1,352 @@
1
1
  import {ActivityApi} from '../Api';
2
2
  import {cloneContent, cloneMessage} from '../messageHelper';
3
3
 
4
- export default function ActivityExecution(activity, context) {
5
- const {id, broker, logger, isSubProcess, Behaviour, environment} = activity;
6
- const {batchSize = 50} = environment.settings;
7
- const postponed = [];
8
-
9
- let source, initMessage, completed = false, executionId;
10
-
11
- const executeQ = broker.assertQueue('execute-q', {durable: true, autoDelete: false});
12
-
13
- const executionApi = {
14
- get completed() {
15
- return completed;
16
- },
17
- get source() {
18
- return source;
19
- },
20
- discard,
21
- execute,
22
- passthrough,
23
- getApi,
24
- getPostponed,
25
- getState,
26
- recover,
27
- stop,
4
+ const kCompleted = Symbol.for('completed');
5
+ const kExecuteQ = Symbol.for('executeQ');
6
+ const kExecuteMessage = Symbol.for('executeMessage');
7
+ const kMessageHandlers = Symbol.for('messageHandlers');
8
+ const kPostponed = Symbol.for('postponed');
9
+
10
+ export default ActivityExecution;
11
+
12
+ function ActivityExecution(activity, context) {
13
+ this.activity = activity;
14
+ this.context = context;
15
+ this.id = activity.id;
16
+ this.broker = activity.broker;
17
+ this[kPostponed] = [];
18
+ this[kCompleted] = false;
19
+ this[kExecuteQ] = this.broker.assertQueue('execute-q', {durable: true, autoDelete: false});
20
+
21
+ this[kMessageHandlers] = {
22
+ onParentApiMessage: this._onParentApiMessage.bind(this),
23
+ onExecuteMessage: this._onExecuteMessage.bind(this),
28
24
  };
25
+ }
29
26
 
30
- return executionApi;
31
-
32
- function getPostponed() {
33
- let apis = postponed.map((msg) => getApi(msg));
34
- if (!isSubProcess || !source) return apis;
35
- apis = apis.concat(source.getPostponed());
36
- return apis;
37
- }
38
-
39
- function execute(executeMessage) {
40
- if (!executeMessage) throw new Error('Execution requires message');
41
- if (!executeMessage.content || !executeMessage.content.executionId) throw new Error('Execution requires execution id');
42
-
43
- const isRedelivered = executeMessage.fields.redelivered;
44
- executionId = executeMessage.content.executionId;
27
+ const proto = ActivityExecution.prototype;
45
28
 
46
- initMessage = cloneMessage(executeMessage);
47
- initMessage.content = {...initMessage.content, executionId, state: 'start', isRootScope: true};
29
+ Object.defineProperty(proto, 'completed', {
30
+ enumerable: true,
31
+ get() {
32
+ return this[kCompleted];
33
+ },
34
+ });
48
35
 
49
- if (isRedelivered) {
50
- postponed.splice(0);
51
- logger.debug(`<${executionId} (${id})> resume execution`);
36
+ proto.execute = function execute(executeMessage) {
37
+ if (!executeMessage) throw new Error('Execution requires message');
38
+ const executionId = executeMessage.content && executeMessage.content.executionId;
39
+ if (!executionId) throw new Error('Execution requires execution id');
52
40
 
53
- if (!source) source = Behaviour(activity, context);
41
+ this.executionId = executionId;
42
+ const initMessage = this[kExecuteMessage] = cloneMessage(executeMessage, {
43
+ executionId,
44
+ state: 'start',
45
+ isRootScope: true,
46
+ });
54
47
 
55
- activate();
56
- return broker.publish('execution', 'execute.resume.execution', cloneContent(initMessage.content), {persistent: false});
57
- }
48
+ if (executeMessage.fields.redelivered) {
49
+ this[kPostponed].splice(0);
50
+ this._debug('resume execution');
58
51
 
59
- logger.debug(`<${executionId} (${id})> execute`);
60
- activate();
61
- source = Behaviour(activity, context);
62
- broker.publish('execution', 'execute.start', cloneContent(initMessage.content));
63
- }
52
+ if (!this.source) this.source = new this.activity.Behaviour(this.activity, this.context);
64
53
 
65
- function passthrough(executeMessage) {
66
- if (!source) return execute(executeMessage);
67
- return source.execute(executeMessage);
54
+ this.activate();
55
+ return this.broker.publish('execution', 'execute.resume.execution', cloneContent(initMessage.content), {persistent: false});
68
56
  }
69
57
 
70
- function discard() {
71
- if (completed) return;
72
- if (!initMessage) return logger.warn(`<${id}> is not executing`);
73
- getApi(initMessage).discard();
58
+ this._debug('execute');
59
+ this.activate();
60
+ this.source = new this.activity.Behaviour(this.activity, this.context);
61
+ this.broker.publish('execution', 'execute.start', cloneContent(initMessage.content));
62
+ };
63
+
64
+ proto.activate = function activate() {
65
+ if (this[kCompleted]) return;
66
+
67
+ const broker = this.broker;
68
+ const batchSize = this.activity.environment.settings.batchSize || 50;
69
+ broker.bindQueue('execute-q', 'execution', 'execute.#', {priority: 100});
70
+
71
+ const {onExecuteMessage, onParentApiMessage} = this[kMessageHandlers];
72
+ this[kExecuteQ].assertConsumer(onExecuteMessage, {
73
+ exclusive: true,
74
+ prefetch: batchSize * 2,
75
+ priority: 100,
76
+ consumerTag: '_activity-execute',
77
+ });
78
+
79
+ if (this[kCompleted]) return this.deactivate();
80
+
81
+ broker.subscribeTmp('api', `activity.*.${this.executionId}`, onParentApiMessage, {
82
+ noAck: true,
83
+ consumerTag: '_activity-api-execution',
84
+ priority: 200,
85
+ });
86
+ };
87
+
88
+ proto.deactivate = function deactivate() {
89
+ const broker = this.broker;
90
+ broker.cancel('_activity-api-execution');
91
+ broker.cancel('_activity-execute');
92
+ broker.unbindQueue('execute-q', 'execution', 'execute.#');
93
+ };
94
+
95
+ proto.discard = function discard() {
96
+ if (this[kCompleted]) return;
97
+ const initMessage = this[kExecuteMessage];
98
+ if (!initMessage) return this.activity.logger.warn(`<${this.id}> is not executing`);
99
+ this.getApi(initMessage).discard();
100
+ };
101
+
102
+ proto.getApi = function getApi(apiMessage) {
103
+ const self = this;
104
+ if (!apiMessage) apiMessage = this[kExecuteMessage];
105
+
106
+ if (self.source.getApi) {
107
+ const sourceApi = self.source.getApi(apiMessage);
108
+ if (sourceApi) return sourceApi;
74
109
  }
75
110
 
76
- function stop() {
77
- if (!initMessage) return;
78
- getApi(initMessage).stop();
79
- }
111
+ const api = ActivityApi(self.broker, apiMessage);
80
112
 
81
- function getState() {
82
- const result = {completed};
113
+ api.getExecuting = function getExecuting() {
114
+ return self[kPostponed].reduce((result, msg) => {
115
+ if (msg.content.executionId === apiMessage.content.executionId) return result;
116
+ result.push(self.getApi(msg));
117
+ return result;
118
+ }, []);
119
+ };
83
120
 
84
- if (!source || !source.getState) return result;
85
- return {...result, ...source.getState()};
86
- }
121
+ return api;
122
+ };
87
123
 
88
- function recover(state) {
89
- postponed.splice(0);
124
+ proto.passthrough = function passthrough(executeMessage) {
125
+ if (!this.source) return this.execute(executeMessage);
126
+ return this._sourceExecute(executeMessage);
127
+ };
90
128
 
91
- if (!state) return executionApi;
92
- if ('completed' in state) completed = state.completed;
129
+ proto.getPostponed = function getPostponed() {
130
+ let apis = this[kPostponed].map((msg) => this.getApi(msg));
131
+ if (!this.activity.isSubProcess || !this.source) return apis;
132
+ apis = apis.concat(this.source.getPostponed());
133
+ return apis;
134
+ };
93
135
 
94
- source = Behaviour(activity, context);
95
- if (source.recover) {
96
- source.recover(state);
97
- }
136
+ proto.getState = function getState() {
137
+ const result = {completed: this[kCompleted]};
138
+ const source = this.source;
98
139
 
99
- return executionApi;
100
- }
101
-
102
- function activate() {
103
- if (completed) return;
140
+ if (!source || !source.getState) return result;
141
+ return {...result, ...source.getState()};
142
+ };
104
143
 
105
- broker.bindQueue(executeQ.name, 'execution', 'execute.#', {priority: 100});
106
- executeQ.assertConsumer(onExecuteMessage, {exclusive: true, prefetch: batchSize * 2, priority: 100, consumerTag: '_activity-execute'});
107
- if (completed) return deactivate();
144
+ proto.recover = function recover(state) {
145
+ this[kPostponed].splice(0);
108
146
 
109
- broker.subscribeTmp('api', `activity.*.${executionId}`, onParentApiMessage, {noAck: true, consumerTag: '_activity-api-execution', priority: 200});
110
- }
147
+ if (!state) return this;
148
+ if ('completed' in state) this[kCompleted] = state.completed;
111
149
 
112
- function deactivate() {
113
- broker.cancel('_activity-api-execution');
114
- broker.cancel('_activity-execute');
115
- broker.unbindQueue(executeQ.name, 'execution', 'execute.#');
150
+ const source = this.source = new this.activity.Behaviour(this.activity, this.context);
151
+ if (source.recover) {
152
+ source.recover(state);
116
153
  }
117
154
 
118
- function onParentApiMessage(routingKey, message) {
119
- const messageType = message.properties.type;
155
+ return this;
156
+ };
120
157
 
121
- switch (messageType) {
122
- case 'discard':
123
- executeQ.queueMessage({routingKey: 'execute.discard'}, cloneContent(initMessage.content));
124
- break;
125
- case 'stop':
126
- onStop(message);
127
- break;
128
- }
129
- }
158
+ proto.stop = function stop() {
159
+ const executeMessage = this[kExecuteMessage];
160
+ if (!executeMessage) return;
161
+ this.getApi(executeMessage).stop();
162
+ };
130
163
 
131
- function onStop(message) {
132
- const stoppedId = message && message.content && message.content.executionId;
133
- const running = getPostponed();
134
- running.forEach((api) => {
135
- if (stoppedId !== api.content.executionId) {
136
- api.stop();
137
- }
138
- });
139
-
140
- broker.cancel('_activity-execute');
141
- broker.cancel('_activity-api-execution');
164
+ proto._sourceExecute = function sourceExecute(executeMessage) {
165
+ try {
166
+ return this.source.execute(executeMessage);
167
+ } catch (error) {
168
+ return this.broker.publish('execution', 'execute.error', cloneContent(executeMessage.content, {error}));
142
169
  }
170
+ };
143
171
 
144
- function onExecuteMessage(routingKey, message) {
145
- const {fields = {}, content = {}, properties = {}} = message;
146
- const isRedelivered = fields.redelivered;
147
- const {isRootScope, ignoreIfExecuting, keep, executionId: cexid, error} = content;
148
- const {persistent, correlationId} = properties;
172
+ proto._onExecuteMessage = function onExecuteMessage(routingKey, message) {
173
+ const {fields, content, properties} = message;
174
+ const isRedelivered = fields.redelivered;
149
175
 
150
- if (isRedelivered && persistent === false) return message.ack();
176
+ if (isRedelivered && properties.persistent === false) return message.ack();
151
177
 
152
- switch (routingKey) {
153
- case 'execute.resume.execution': {
154
- if (!postponed.length) return broker.publish('execution', 'execute.start', cloneContent(initMessage.content));
155
- break;
156
- }
157
- case 'execute.error':
158
- case 'execute.discard':
159
- executionDiscard();
160
- break;
161
- case 'execute.cancel':
162
- case 'execute.completed': {
163
- if (isRedelivered) {
164
- message.ack();
165
- return broker.publish('execution', routingKey, getExecuteMessage().content);
166
- }
167
-
168
- executionCompleted();
169
- break;
170
- }
171
- case 'execute.start': {
172
- if (!stateChangeMessage()) return;
173
- return source.execute(getExecuteMessage());
178
+ switch (routingKey) {
179
+ case 'execute.resume.execution': {
180
+ if (!this[kPostponed].length) return this.broker.publish('execution', 'execute.start', cloneContent(this[kExecuteMessage].content));
181
+ break;
182
+ }
183
+ case 'execute.error':
184
+ case 'execute.discard':
185
+ return this._onExecutionDiscarded(message);
186
+ case 'execute.cancel':
187
+ case 'execute.completed': {
188
+ if (isRedelivered) {
189
+ message.ack();
190
+ return this.broker.publish('execution', routingKey, getExecuteMessage(message).content);
174
191
  }
175
- case 'execute.outbound.take': {
176
- if (isRedelivered) {
177
- message.ack();
178
- break;
179
- }
180
- broker.publish('execution', 'execution.outbound.take', cloneContent(content), {type: 'outbound'});
192
+
193
+ return this._onExecutionCompleted(message);
194
+ }
195
+ case 'execute.start': {
196
+ if (!this._onStateChangeMessage(message)) return;
197
+ return this._sourceExecute(getExecuteMessage(message));
198
+ }
199
+ case 'execute.outbound.take': {
200
+ if (isRedelivered) {
201
+ message.ack();
181
202
  break;
182
203
  }
183
- default: {
184
- if (!stateChangeMessage()) return;
185
- if (isRedelivered) {
186
- return source.execute(getExecuteMessage());
187
- }
188
- }
204
+ this.broker.publish('execution', 'execution.outbound.take', cloneContent(content), {type: 'outbound'});
205
+ break;
189
206
  }
190
-
191
- function stateChangeMessage() {
192
- const idx = postponed.findIndex((msg) => msg.content.executionId === cexid);
193
- let previousMsg;
194
- if (idx > -1) {
195
- if (ignoreIfExecuting) {
196
- message.ack();
197
- return false;
198
- }
199
-
200
- previousMsg = postponed.splice(idx, 1, message)[0];
201
- previousMsg.ack();
202
-
203
- return true;
207
+ default: {
208
+ if (!this._onStateChangeMessage(message)) return;
209
+ if (isRedelivered) {
210
+ return this._sourceExecute(getExecuteMessage(message));
204
211
  }
205
-
206
- postponed.push(message);
207
- return true;
208
212
  }
209
-
210
- function getExecuteMessage() {
211
- const result = cloneMessage(message, {...(isRedelivered ? {isRecovered: true} : undefined)});
212
- result.content.ignoreIfExecuting = undefined;
213
- return result;
213
+ }
214
+ };
215
+
216
+ proto._onStateChangeMessage = function onStateChangeMessage(message) {
217
+ const {ignoreIfExecuting, executionId} = message.content;
218
+ const postponed = this[kPostponed];
219
+ const idx = postponed.findIndex((msg) => msg.content.executionId === executionId);
220
+ let previousMsg;
221
+ if (idx > -1) {
222
+ if (ignoreIfExecuting) {
223
+ message.ack();
224
+ return false;
214
225
  }
215
226
 
216
- function executionCompleted() {
217
- const postponedMsg = ackPostponed(message);
218
- if (!postponedMsg) return;
219
-
220
- if (!isRootScope) {
221
- logger.debug(`<${cexid} (${id})> completed sub execution`);
222
- if (!keep) message.ack();
223
- if (postponed.length === 1 && postponed[0].content.isRootScope && !postponed[0].content.preventComplete) {
224
- return broker.publish('execution', 'execute.completed', cloneContent(postponed[0].content));
225
- }
226
- return;
227
- }
228
-
229
- logger.debug(`<${cexid} (${id})> completed execution`);
230
- completed = true;
227
+ previousMsg = postponed.splice(idx, 1, message)[0];
228
+ previousMsg.ack();
231
229
 
232
- message.ack(true);
233
-
234
- deactivate();
235
-
236
- const subApis = getPostponed();
237
- postponed.splice(0);
238
- subApis.forEach((api) => api.discard());
230
+ return true;
231
+ }
239
232
 
240
- publishExecutionCompleted('completed', {...postponedMsg.content, ...message.content});
233
+ postponed.push(message);
234
+ return true;
235
+ };
236
+
237
+ proto._onExecutionCompleted = function onExecutionCompleted(message) {
238
+ const postponedMsg = this._ackPostponed(message);
239
+ if (!postponedMsg) return;
240
+ const postponed = this[kPostponed];
241
+
242
+ const {executionId, keep, isRootScope} = message.content;
243
+ if (!isRootScope) {
244
+ this._debug('completed sub execution');
245
+ if (!keep) message.ack();
246
+ if (postponed.length === 1 && postponed[0].content.isRootScope && !postponed[0].content.preventComplete) {
247
+ return this.broker.publish('execution', 'execute.completed', cloneContent(postponed[0].content));
241
248
  }
249
+ return;
250
+ }
242
251
 
243
- function executionDiscard() {
244
- const postponedMsg = ackPostponed(message);
245
- if (!isRootScope && !postponedMsg) return;
252
+ this._debug('completed execution', executionId);
253
+ this[kCompleted] = true;
246
254
 
247
- if (!error && !isRootScope) {
248
- message.ack();
249
- if (postponed.length === 1 && postponed[0].content.isRootScope) {
250
- return broker.publish('execution', 'execute.discard', {...postponed[0].content}, {correlationId});
251
- }
252
- return;
253
- }
255
+ message.ack(true);
254
256
 
255
- message.ack(true);
257
+ this.deactivate();
256
258
 
257
- deactivate();
259
+ const subApis = this.getPostponed();
260
+ postponed.splice(0);
261
+ for (const api of subApis) api.discard();
258
262
 
259
- const subApis = getPostponed();
260
- postponed.splice(0);
261
- subApis.forEach((api) => api.discard());
263
+ this._publishExecutionCompleted('completed', {...postponedMsg.content, ...message.content}, message.properties.correlationId);
264
+ };
262
265
 
263
- publishExecutionCompleted(error ? 'error' : 'discard', {...content});
264
- }
266
+ proto._onExecutionDiscarded = function onExecutionDiscarded(message) {
267
+ const postponedMsg = this._ackPostponed(message);
268
+ const {isRootScope, error} = message.content;
269
+ if (!isRootScope && !postponedMsg) return;
265
270
 
266
- function publishExecutionCompleted(completionType, completeContent) {
267
- completed = true;
268
-
269
- broker.publish('execution', `execution.${completionType}`, {
270
- ...completeContent,
271
- state: completionType,
272
- }, {type: completionType, correlationId});
271
+ const postponed = this[kPostponed];
272
+ const correlationId = message.properties.correlationId;
273
+ if (!error && !isRootScope) {
274
+ message.ack();
275
+ if (postponed.length === 1 && postponed[0].content.isRootScope) {
276
+ return this.broker.publish('execution', 'execute.discard', postponed[0].content, {correlationId});
273
277
  }
278
+ return;
274
279
  }
275
280
 
276
- function ackPostponed(completeMessage) {
277
- const {executionId: eid} = completeMessage.content;
278
-
279
- const idx = postponed.findIndex(({content}) => content.executionId === eid);
280
- if (idx === -1) return;
281
- const [msg] = postponed.splice(idx, 1);
282
- msg.ack();
283
- return msg;
284
- }
285
-
286
- function getApi(apiMessage) {
287
- if (!apiMessage) apiMessage = initMessage;
281
+ message.ack(true);
288
282
 
289
- if (source.getApi) {
290
- const sourceApi = source.getApi(apiMessage);
291
- if (sourceApi) return sourceApi;
292
- }
283
+ this.deactivate();
293
284
 
294
- const api = ActivityApi(broker, apiMessage);
285
+ const subApis = this.getPostponed();
286
+ postponed.splice(0);
287
+ for (const api of subApis) api.discard();
295
288
 
296
- api.getExecuting = function getExecuting() {
297
- return postponed.reduce((result, msg) => {
298
- if (msg.content.executionId === apiMessage.content.executionId) return result;
299
- result.push(getApi(msg));
300
- return result;
301
- }, []);
302
- };
289
+ if (error) {
290
+ return this._publishExecutionCompleted('error', cloneContent(message.content, {error}), correlationId);
291
+ }
303
292
 
304
- return api;
293
+ this._publishExecutionCompleted('discard', message.content, correlationId);
294
+ };
295
+
296
+ proto._publishExecutionCompleted = function publishExecutionCompleted(completionType, completeContent, correlationId) {
297
+ this[kCompleted] = true;
298
+
299
+ this.broker.publish('execution', `execution.${completionType}`, {
300
+ ...completeContent,
301
+ state: completionType,
302
+ }, {type: completionType, correlationId});
303
+ };
304
+
305
+ proto._ackPostponed = function ackPostponed(completeMessage) {
306
+ const {executionId: eid} = completeMessage.content;
307
+
308
+ const postponed = this[kPostponed];
309
+ const idx = postponed.findIndex(({content: c}) => c.executionId === eid);
310
+ if (idx === -1) return;
311
+ const [msg] = postponed.splice(idx, 1);
312
+ msg.ack();
313
+ return msg;
314
+ };
315
+
316
+ proto._onParentApiMessage = function onParentApiMessage(routingKey, message) {
317
+ switch (message.properties.type) {
318
+ case 'error':
319
+ return this[kExecuteQ].queueMessage({routingKey: 'execute.error'}, {error: message.content.error});
320
+ case 'discard':
321
+ return this[kExecuteQ].queueMessage({routingKey: 'execute.discard'}, cloneContent(this[kExecuteMessage].content));
322
+ case 'stop': {
323
+ return this._onStop(message);
324
+ }
305
325
  }
326
+ };
327
+
328
+ proto._onStop = function onStop(message) {
329
+ const stoppedId = message && message.content && message.content.executionId;
330
+ const running = this.getPostponed();
331
+ for (const api of running) {
332
+ if (stoppedId !== api.content.executionId) {
333
+ api.stop();
334
+ }
335
+ }
336
+
337
+ this.broker.cancel('_activity-execute');
338
+ this.broker.cancel('_activity-api-execution');
339
+ };
340
+
341
+ proto._debug = function debug(logMessage, executionId) {
342
+ executionId = executionId || this.executionId;
343
+ this.activity.logger.debug(`<${executionId} (${this.id})> ${logMessage}`);
344
+ };
345
+
346
+ function getExecuteMessage(message) {
347
+ const result = cloneMessage(message, {
348
+ ...(message.fields.redelivered ? {isRecovered: true} : undefined),
349
+ ignoreIfExecuting: undefined,
350
+ });
351
+ return result;
306
352
  }
@@ -1,13 +1,13 @@
1
1
  import {cloneParent} from '../messageHelper';
2
2
 
3
3
  export default function DummyActivity(activityDef) {
4
- const {id, type = 'dummy', name, parent: originalParent = {}, behaviour = {}} = activityDef;
4
+ const {id, type = 'dummy', name, parent, behaviour} = activityDef;
5
5
  return {
6
6
  id,
7
7
  type,
8
8
  name,
9
9
  behaviour: {...behaviour},
10
- parent: cloneParent(originalParent),
10
+ parent: cloneParent(parent),
11
11
  placeholder: true,
12
12
  };
13
13
  }