bpmn-elements 6.0.1 → 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 (116) hide show
  1. package/CHANGELOG.md +322 -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 +169 -175
  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/activity/Activity.js +1106 -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 +722 -409
  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 +433 -359
  49. package/dist/src/process/ProcessExecution.js +744 -645
  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 +195 -175
  60. package/dist/src/tasks/Task.js +17 -19
  61. package/index.js +2 -0
  62. package/package.json +13 -13
  63. package/src/Api.js +65 -59
  64. package/src/Context.js +138 -141
  65. package/src/Environment.js +88 -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 +915 -775
  70. package/src/activity/ActivityExecution.js +293 -247
  71. package/src/activity/Dummy.js +2 -2
  72. package/src/definition/Definition.js +436 -401
  73. package/src/definition/DefinitionExecution.js +603 -343
  74. package/src/error/Errors.js +11 -6
  75. package/src/eventDefinitions/CancelEventDefinition.js +164 -121
  76. package/src/eventDefinitions/CompensateEventDefinition.js +158 -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 +16 -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 +374 -333
  106. package/src/process/ProcessExecution.js +606 -554
  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
@@ -13,169 +13,203 @@ var _messageHelper = require("../messageHelper");
13
13
 
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
+ const completedSymbol = Symbol.for('completed');
17
+ const messageQSymbol = Symbol.for('messageQ');
18
+ const executeMessageSymbol = Symbol.for('executeMessage');
19
+ const referenceElementSymbol = Symbol.for('referenceElement');
20
+ const referenceInfoSymbol = Symbol.for('reference');
21
+
16
22
  function EscalationEventDefinition(activity, eventDefinition) {
17
23
  const {
18
24
  id,
19
25
  broker,
20
26
  environment,
21
- isThrowing,
22
- getActivityById
27
+ isThrowing
23
28
  } = activity;
24
29
  const {
25
30
  type,
26
31
  behaviour = {}
27
32
  } = eventDefinition;
28
- const {
29
- debug
30
- } = environment.Logger(type.toLowerCase());
31
- const reference = behaviour.escalationRef || {
32
- name: 'anonymous'
33
- };
34
- const referenceElement = reference.id && getActivityById(reference.id);
35
- const escalationId = referenceElement ? referenceElement.id : 'anonymous';
36
- const escalationQueueName = `escalate-${(0, _shared.brokerSafeId)(id)}-${(0, _shared.brokerSafeId)(escalationId)}-q`;
37
- if (!isThrowing) setupCatch();
38
- const source = {
39
- id,
40
- type,
41
- reference: { ...reference,
42
- referenceType: 'escalate'
43
- },
44
- execute: isThrowing ? executeThrow : executeCatch
33
+ this.id = id;
34
+ this.type = type;
35
+ const reference = this.reference = {
36
+ name: 'anonymous',
37
+ ...behaviour.escalationRef,
38
+ referenceType: 'escalate'
45
39
  };
46
- return source;
47
-
48
- function executeCatch(executeMessage) {
49
- let completed;
50
- const messageContent = (0, _messageHelper.cloneContent)(executeMessage.content);
51
- const {
52
- executionId,
53
- parent
54
- } = messageContent;
55
- const parentExecutionId = parent && parent.executionId;
56
- const {
57
- message: referenceMessage,
58
- description
59
- } = resolveMessage(executeMessage);
60
- broker.consume(escalationQueueName, onEscalationApiMessage, {
61
- noAck: true,
62
- consumerTag: `_onescalate-${executionId}`
63
- });
64
- if (completed) return;
65
- broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
66
- noAck: true,
67
- consumerTag: `_api-${executionId}`
40
+ this.isThrowing = isThrowing;
41
+ this.activity = activity;
42
+ this.broker = broker;
43
+ this.logger = environment.Logger(type.toLowerCase());
44
+ const referenceElement = this[referenceElementSymbol] = reference.id && activity.getActivityById(reference.id);
45
+
46
+ if (!isThrowing) {
47
+ this[completedSymbol] = false;
48
+ const referenceId = referenceElement ? referenceElement.id : 'anonymous';
49
+ const messageQueueName = `${reference.referenceType}-${(0, _shared.brokerSafeId)(id)}-${(0, _shared.brokerSafeId)(referenceId)}-q`;
50
+ this[messageQSymbol] = broker.assertQueue(messageQueueName, {
51
+ autoDelete: false,
52
+ durable: true
68
53
  });
69
- if (completed) return stop();
70
- debug(`<${executionId} (${id})> expect ${description}`);
71
- broker.publish('event', 'activity.wait', { ...messageContent,
72
- executionId: parentExecutionId,
73
- parent: (0, _messageHelper.shiftParent)(parent),
74
- escalation: { ...referenceMessage
75
- }
54
+ broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, {
55
+ durable: true,
56
+ priority: 400
76
57
  });
58
+ }
59
+ }
60
+
61
+ const proto = EscalationEventDefinition.prototype;
62
+ Object.defineProperty(proto, 'executionId', {
63
+ get() {
64
+ const message = this[executeMessageSymbol];
65
+ return message && message.content.executionId;
66
+ }
67
+
68
+ });
69
+
70
+ proto.execute = function execute(executeMessage) {
71
+ return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
72
+ };
77
73
 
78
- function onEscalationApiMessage(routingKey, message) {
79
- if ((0, _getPropertyValue.default)(message, 'content.message.id') !== referenceMessage.id) return;
80
- const output = message.content.message;
81
- completed = true;
82
- stop();
83
- debug(`<${executionId} (${id})> caught ${description}`);
84
- broker.publish('event', 'activity.catch', { ...messageContent,
85
- message: { ...output
86
- },
87
- executionId: parentExecutionId,
88
- parent: (0, _messageHelper.shiftParent)(executeMessage.content.parent)
89
- }, {
90
- type: 'catch'
91
- });
92
- return broker.publish('execution', 'execute.completed', { ...messageContent,
93
- output,
94
- state: 'catch'
95
- });
74
+ proto.executeCatch = function executeCatch(executeMessage) {
75
+ this[executeMessageSymbol] = executeMessage;
76
+ this[completedSymbol] = false;
77
+ const executeContent = executeMessage.content;
78
+ const {
79
+ executionId,
80
+ parent
81
+ } = executeContent;
82
+
83
+ const info = this[referenceInfoSymbol] = this._getReferenceInfo(executeMessage);
84
+
85
+ const broker = this.broker;
86
+ this[messageQSymbol].consume(this._onCatchMessage.bind(this), {
87
+ noAck: true,
88
+ consumerTag: `_onescalate-${executionId}`
89
+ });
90
+ if (this[completedSymbol]) return;
91
+ broker.subscribeTmp('api', `activity.#.${executionId}`, this._onApiMessage.bind(this), {
92
+ noAck: true,
93
+ consumerTag: `_api-${executionId}`
94
+ });
95
+
96
+ this._debug(`expect ${info.description}`);
97
+
98
+ const waitContent = (0, _messageHelper.cloneContent)(executeContent, {
99
+ executionId: parent.executionId,
100
+ parent: (0, _messageHelper.shiftParent)(parent),
101
+ escalation: { ...info.message
96
102
  }
103
+ });
104
+ waitContent.parent = (0, _messageHelper.shiftParent)(parent);
105
+ broker.publish('event', 'activity.wait', waitContent);
106
+ };
97
107
 
98
- function onApiMessage(routingKey, message) {
99
- const messageType = message.properties.type;
100
-
101
- switch (messageType) {
102
- case 'escalate':
103
- {
104
- return onEscalationApiMessage(routingKey, message);
105
- }
106
-
107
- case 'discard':
108
- {
109
- completed = true;
110
- stop();
111
- return broker.publish('execution', 'execute.discard', { ...messageContent
112
- });
113
- }
114
-
115
- case 'stop':
116
- {
117
- stop();
118
- break;
119
- }
108
+ proto.executeThrow = function executeThrow(executeMessage) {
109
+ const executeContent = executeMessage.content;
110
+ const {
111
+ executionId,
112
+ parent
113
+ } = executeContent;
114
+
115
+ const info = this._getReferenceInfo(executeMessage);
116
+
117
+ this.logger.debug(`<${executionId} (${this.activity.id})> escalate ${info.description}`);
118
+ const broker = this.broker;
119
+ const throwContent = (0, _messageHelper.cloneContent)(executeContent, {
120
+ executionId: parent.executionId,
121
+ message: info.message,
122
+ state: 'throw'
123
+ });
124
+ throwContent.parent = (0, _messageHelper.shiftParent)(parent);
125
+ broker.publish('event', 'activity.escalate', throwContent, {
126
+ type: 'escalate',
127
+ delegate: true
128
+ });
129
+ return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeContent));
130
+ };
131
+
132
+ proto._onCatchMessage = function onCatchMessage(routingKey, message) {
133
+ const info = this[referenceInfoSymbol];
134
+ if ((0, _getPropertyValue.default)(message, 'content.message.id') !== info.message.id) return;
135
+ const output = message.content.message;
136
+ this[completedSymbol] = true;
137
+
138
+ this._stop();
139
+
140
+ this._debug(`caught ${info.description}`);
141
+
142
+ const executeContent = this[executeMessageSymbol].content;
143
+ const {
144
+ parent,
145
+ ...content
146
+ } = executeContent;
147
+ const catchContent = (0, _messageHelper.cloneContent)(content, {
148
+ message: { ...output
149
+ },
150
+ executionId: parent.executionId
151
+ });
152
+ catchContent.parent = (0, _messageHelper.shiftParent)(parent);
153
+ const broker = this.broker;
154
+ broker.publish('event', 'activity.catch', catchContent, {
155
+ type: 'catch'
156
+ });
157
+ return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeContent, {
158
+ output,
159
+ state: 'catch'
160
+ }));
161
+ };
162
+
163
+ proto._onApiMessage = function onApiMessage(routingKey, message) {
164
+ switch (message.properties.type) {
165
+ case 'escalate':
166
+ {
167
+ return this._onCatchMessage(routingKey, message);
120
168
  }
121
- }
122
169
 
123
- function stop() {
124
- broker.cancel(`_api-${executionId}`);
125
- broker.cancel(`_onescalate-${executionId}`);
126
- }
127
- }
170
+ case 'discard':
171
+ {
172
+ this[completedSymbol] = true;
128
173
 
129
- function executeThrow(executeMessage) {
130
- const messageContent = (0, _messageHelper.cloneContent)(executeMessage.content);
131
- const {
132
- executionId,
133
- parent
134
- } = messageContent;
135
- const parentExecutionId = parent && parent.executionId;
136
- const {
137
- message: referenceMessage,
138
- description
139
- } = resolveMessage(executeMessage);
140
- debug(`<${executionId} (${id})> escalate ${description}`);
141
- broker.publish('event', 'activity.escalate', { ...(0, _messageHelper.cloneContent)(messageContent),
142
- executionId: parentExecutionId,
143
- parent: (0, _messageHelper.shiftParent)(parent),
144
- message: { ...referenceMessage
145
- },
146
- state: 'throw'
147
- }, {
148
- type: 'escalate',
149
- delegate: true
150
- });
151
- return broker.publish('execution', 'execute.completed', { ...messageContent
152
- });
174
+ this._stop();
175
+
176
+ return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[executeMessageSymbol].content));
177
+ }
178
+
179
+ case 'stop':
180
+ {
181
+ this._stop();
182
+
183
+ break;
184
+ }
153
185
  }
186
+ };
154
187
 
155
- function resolveMessage(message) {
156
- if (!referenceElement) {
157
- return {
158
- message: { ...reference
159
- },
160
- description: 'anonymous escalation'
161
- };
162
- }
188
+ proto._stop = function stop() {
189
+ const broker = this.broker,
190
+ executionId = this.executionId;
191
+ broker.cancel(`_api-${executionId}`);
192
+ broker.cancel(`_onescalate-${executionId}`);
193
+ };
163
194
 
164
- const result = {
165
- message: referenceElement.resolve(message)
195
+ proto._getReferenceInfo = function getReferenceInfo(message) {
196
+ const referenceElement = this[referenceElementSymbol];
197
+
198
+ if (!referenceElement) {
199
+ return {
200
+ message: { ...this.reference
201
+ },
202
+ description: 'anonymous escalation'
166
203
  };
167
- result.description = `${result.message.name} <${result.message.id}>`;
168
- return result;
169
204
  }
170
205
 
171
- function setupCatch() {
172
- broker.assertQueue(escalationQueueName, {
173
- autoDelete: false,
174
- durable: true
175
- });
176
- broker.bindQueue(escalationQueueName, 'api', '*.escalate.#', {
177
- durable: true,
178
- priority: 400
179
- });
180
- }
181
- }
206
+ const result = {
207
+ message: referenceElement.resolve(message)
208
+ };
209
+ result.description = `${result.message.name} <${result.message.id}>`;
210
+ return result;
211
+ };
212
+
213
+ proto._debug = function debug(msg) {
214
+ this.logger.debug(`<${this.executionId} (${this.activity.id})> ${msg}`);
215
+ };
@@ -7,137 +7,165 @@ exports.default = EventDefinitionExecution;
7
7
 
8
8
  var _messageHelper = require("../messageHelper");
9
9
 
10
+ const completedSymbol = Symbol.for('completed');
11
+ const executeMessageSymbol = Symbol.for('executeMessage');
12
+ const stoppedSymbol = Symbol.for('stopped');
13
+
10
14
  function EventDefinitionExecution(activity, eventDefinitions, completedRoutingKey = 'execute.completed') {
11
- const {
12
- id,
13
- broker,
14
- logger
15
- } = activity;
16
- const executeConsumerTag = '_eventdefinition-execution-execute-tag';
17
- const apiConsumerTag = '_eventdefinition-execution-api-tag';
18
- let parentExecutionContent,
19
- parent,
20
- completed = false,
21
- stopped = false;
22
- return {
23
- execute,
24
-
25
- get completed() {
26
- return completed;
27
- }
28
-
29
- };
30
-
31
- function execute(executeMessage) {
32
- const executeContent = executeMessage.content;
33
- const isRedelivered = executeMessage.fields.redelivered;
34
- const {
35
- isRootScope,
36
- isDefinitionScope,
37
- executionId: messageExecutionId
38
- } = executeContent;
39
- if (isDefinitionScope) return executeDefinition();
40
- let parentExecutionId;
41
-
42
- if (isRootScope) {
43
- parentExecutionId = messageExecutionId;
44
- parentExecutionContent = executeContent;
45
- broker.subscribeTmp('execution', 'execute.#', onExecuteMessage, {
46
- noAck: true,
47
- consumerTag: executeConsumerTag,
48
- priority: 300
49
- });
50
- broker.subscribeTmp('api', `activity.*.${parentExecutionId}`, onApiMessage, {
51
- noAck: true,
52
- consumerTag: apiConsumerTag,
53
- priority: 300
54
- });
55
- parent = (0, _messageHelper.unshiftParent)(parentExecutionContent.parent, parentExecutionContent);
56
- broker.publish('execution', 'execute.update', { ...(0, _messageHelper.cloneContent)(parentExecutionContent),
57
- preventComplete: true
58
- });
59
- }
60
-
61
- if (isRedelivered) return;
62
-
63
- for (let index = 0; index < eventDefinitions.length; ++index) {
64
- if (completed) break;
65
- if (stopped) break;
66
- const ed = eventDefinitions[index];
67
- const executionId = `${messageExecutionId}_${index}`;
68
- logger.debug(`<${messageExecutionId} (${id})> start event definition ${ed.type}, index ${index}`);
69
- broker.publish('execution', 'execute.start', { ...(0, _messageHelper.cloneContent)(parentExecutionContent),
70
- isRootScope: undefined,
71
- type: ed.type,
72
- executionId,
73
- isDefinitionScope: true,
74
- index,
75
- parent
76
- });
77
- }
78
-
79
- function onApiMessage(_, message) {
80
- const messageType = message.properties.type;
81
-
82
- switch (messageType) {
83
- case 'stop':
84
- stopped = true;
85
-
86
- case 'discard':
87
- return stop();
88
- }
89
- }
90
-
91
- function onExecuteMessage(routingKey, message) {
92
- const {
93
- correlationId
94
- } = message.properties;
95
-
96
- switch (routingKey) {
97
- case 'execute.completed':
98
- {
99
- stop();
100
- if (message.content.isDefinitionScope) return complete();
101
- break;
102
- }
103
-
104
- case 'execute.discard':
105
- {
106
- if (message.content.isDefinitionScope) {
107
- logger.debug(`<${message.content.executionId} (${id})> event definition ${message.content.type} discarded, index ${message.content.index}`);
108
- break;
109
- }
110
-
111
- stop();
112
- logger.debug(`<${message.content.executionId} (${id})> event definition parent execution discarded`);
113
- break;
114
- }
15
+ this.id = activity.id;
16
+ this.activity = activity;
17
+ this.broker = activity.broker;
18
+ this.eventDefinitions = eventDefinitions;
19
+ this.completedRoutingKey = completedRoutingKey;
20
+ this[completedSymbol] = false;
21
+ this[stoppedSymbol] = false;
22
+ this[executeMessageSymbol] = null;
23
+ }
24
+
25
+ const proto = EventDefinitionExecution.prototype;
26
+ Object.defineProperty(proto, 'completed', {
27
+ enumerable: true,
28
+
29
+ get() {
30
+ return this[completedSymbol];
31
+ }
32
+
33
+ });
34
+ Object.defineProperty(proto, 'stopped', {
35
+ enumerable: true,
36
+
37
+ get() {
38
+ return this[stoppedSymbol];
39
+ }
40
+
41
+ });
42
+
43
+ proto.execute = function execute(executeMessage) {
44
+ const content = executeMessage.content;
45
+ if (content.isDefinitionScope) return this._executeDefinition(executeMessage);
46
+ if (!content.isRootScope) return;
47
+ const broker = this.broker;
48
+ this[executeMessageSymbol] = executeMessage;
49
+ const executionId = content.executionId;
50
+ broker.subscribeTmp('execution', 'execute.#', this._onExecuteMessage.bind(this), {
51
+ noAck: true,
52
+ consumerTag: '_eventdefinition-execution-execute-tag',
53
+ priority: 300
54
+ });
55
+ broker.subscribeTmp('api', `activity.*.${executionId}`, this._onApiMessage.bind(this), {
56
+ noAck: true,
57
+ consumerTag: '_eventdefinition-execution-api-tag',
58
+ priority: 300
59
+ });
60
+ broker.publish('execution', 'execute.update', (0, _messageHelper.cloneContent)(content, {
61
+ preventComplete: true
62
+ }));
63
+ if (executeMessage.fields.redelivered) return;
64
+ const parent = (0, _messageHelper.unshiftParent)(content.parent, content);
65
+ const eventDefinitions = this.eventDefinitions;
66
+
67
+ for (let index = 0; index < eventDefinitions.length; ++index) {
68
+ if (this[completedSymbol]) break;
69
+ if (this[stoppedSymbol]) break;
70
+ const ed = eventDefinitions[index];
71
+ const edExecutionId = `${executionId}_${index}`;
72
+
73
+ this._debug(executionId, `start event definition ${ed.type}, index ${index}`);
74
+
75
+ const edContent = (0, _messageHelper.cloneContent)(content, {
76
+ isRootScope: undefined,
77
+ type: ed.type,
78
+ executionId: edExecutionId,
79
+ isDefinitionScope: true,
80
+ index
81
+ });
82
+ edContent.parent = (0, _messageHelper.cloneParent)(parent);
83
+ broker.publish('execution', 'execute.start', edContent);
84
+ }
85
+ };
86
+
87
+ proto._onApiMessage = function onApiMessage(_, message) {
88
+ const messageType = message.properties.type;
89
+
90
+ switch (messageType) {
91
+ case 'stop':
92
+ case 'discard':
93
+ return this._stop();
94
+ }
95
+ };
96
+
97
+ proto._onExecuteMessage = function onExecuteMessage(routingKey, message) {
98
+ switch (routingKey) {
99
+ case 'execute.completed':
100
+ {
101
+ this._stop();
102
+
103
+ if (message.content.isDefinitionScope) return this._complete(message);
104
+ break;
115
105
  }
116
106
 
117
- function complete() {
118
- const content = (0, _messageHelper.cloneContent)(message.content);
119
- completed = true;
120
- logger.debug(`<${content.executionId} (${id})> event definition ${content.type} completed, index ${content.index}`);
121
- broker.publish('execution', completedRoutingKey, { ...(0, _messageHelper.cloneContent)(content),
122
- executionId: parentExecutionId,
123
- isRootScope: true,
124
- parent: (0, _messageHelper.shiftParent)(content.parent)
125
- }, {
126
- correlationId
127
- });
107
+ case 'execute.discard':
108
+ {
109
+ const {
110
+ executionId,
111
+ isDefinitionScope
112
+ } = message.content;
113
+
114
+ if (isDefinitionScope) {
115
+ this._debug(executionId, `event definition ${message.content.type} discarded, index ${message.content.index}`);
116
+
117
+ break;
118
+ }
119
+
120
+ this._stop();
121
+
122
+ this._debug(executionId, 'event definition parent execution discarded');
123
+
124
+ break;
128
125
  }
129
- }
130
-
131
- function executeDefinition() {
132
- const ed = eventDefinitions[executeContent.index];
133
- if (!ed) return logger.warn(`<${messageExecutionId} (${id})> found no event definition on index ${executeContent.index}`);
134
- logger.debug(`<${messageExecutionId} (${id})> execute event definition ${ed.type}, index ${executeContent.index}`);
135
- ed.execute(executeMessage);
136
- }
137
-
138
- function stop() {
139
- broker.cancel(executeConsumerTag);
140
- broker.cancel(apiConsumerTag);
141
- }
142
126
  }
143
- }
127
+ };
128
+
129
+ proto._complete = function complete(message) {
130
+ const {
131
+ executionId,
132
+ type,
133
+ index,
134
+ parent
135
+ } = message.content;
136
+ this[completedSymbol] = true;
137
+
138
+ this._debug(executionId, `event definition ${type} completed, index ${index}`);
139
+
140
+ const completeContent = (0, _messageHelper.cloneContent)(message.content, {
141
+ executionId: this[executeMessageSymbol].content.executionId,
142
+ isRootScope: true
143
+ });
144
+ completeContent.parent = (0, _messageHelper.shiftParent)(parent);
145
+ this.broker.publish('execution', this.completedRoutingKey, completeContent, {
146
+ correlationId: message.properties.correlationId
147
+ });
148
+ };
149
+
150
+ proto._executeDefinition = function executeDefinition(message) {
151
+ const {
152
+ executionId,
153
+ index
154
+ } = message.content;
155
+ const ed = this.eventDefinitions[index];
156
+ if (!ed) return this.activity.logger.warn(`<${executionId} (${this.id})> found no event definition on index ${index}`);
157
+
158
+ this._debug(executionId, `execute event definition ${ed.type}, index ${index}`);
159
+
160
+ ed.execute(message);
161
+ };
162
+
163
+ proto._stop = function stop() {
164
+ this[stoppedSymbol] = true;
165
+ this.broker.cancel('_eventdefinition-execution-execute-tag');
166
+ this.broker.cancel('_eventdefinition-execution-api-tag');
167
+ };
168
+
169
+ proto._debug = function debug(executionId, msg) {
170
+ this.activity.logger.debug(`<${executionId} (${this.id})> ${msg}`);
171
+ };