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
@@ -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 completedSymbol = Symbol.for('completed');
5
+ const executeQSymbol = Symbol.for('executeQ');
6
+ const executeMessageSymbol = Symbol.for('executeMessage');
7
+ const messageHandlersSymbol = Symbol.for('messageHandlers');
8
+ const postponedSymbol = 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[postponedSymbol] = [];
18
+ this[completedSymbol] = false;
19
+ this[executeQSymbol] = this.broker.assertQueue('execute-q', {durable: true, autoDelete: false});
20
+
21
+ this[messageHandlersSymbol] = {
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[completedSymbol];
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[executeMessageSymbol] = 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[postponedSymbol].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[completedSymbol]) 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[messageHandlersSymbol];
72
+ this[executeQSymbol].assertConsumer(onExecuteMessage, {
73
+ exclusive: true,
74
+ prefetch: batchSize * 2,
75
+ priority: 100,
76
+ consumerTag: '_activity-execute',
77
+ });
78
+
79
+ if (this[completedSymbol]) 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[completedSymbol]) return;
97
+ const initMessage = this[executeMessageSymbol];
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[executeMessageSymbol];
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[postponedSymbol].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[postponedSymbol].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[completedSymbol]};
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[postponedSymbol].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[completedSymbol] = 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[executeMessageSymbol];
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[postponedSymbol].length) return this.broker.publish('execution', 'execute.start', cloneContent(this[executeMessageSymbol].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[postponedSymbol];
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[postponedSymbol];
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[completedSymbol] = 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[postponedSymbol];
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[completedSymbol] = 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[postponedSymbol];
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[executeQSymbol].queueMessage({routingKey: 'execute.error'}, {error: message.content.error});
320
+ case 'discard':
321
+ return this[executeQSymbol].queueMessage({routingKey: 'execute.discard'}, cloneContent(this[executeMessageSymbol].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
  }