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
@@ -2,134 +2,172 @@ import getPropertyValue from '../getPropertyValue';
2
2
  import {brokerSafeId} from '../shared';
3
3
  import {cloneContent, shiftParent} from '../messageHelper';
4
4
 
5
+ const completedSymbol = Symbol.for('completed');
6
+ const messageQSymbol = Symbol.for('messageQ');
7
+ const executeMessageSymbol = Symbol.for('executeMessage');
8
+ const referenceElementSymbol = Symbol.for('referenceElement');
9
+ const referenceInfoSymbol = Symbol.for('reference');
10
+
5
11
  export default function EscalationEventDefinition(activity, eventDefinition) {
6
- const {id, broker, environment, isThrowing, getActivityById} = activity;
12
+ const {id, broker, environment, isThrowing} = activity;
7
13
  const {type, behaviour = {}} = eventDefinition;
8
- const {debug} = environment.Logger(type.toLowerCase());
9
- const reference = behaviour.escalationRef || {name: 'anonymous'};
10
- const referenceElement = reference.id && getActivityById(reference.id);
11
- const escalationId = referenceElement ? referenceElement.id : 'anonymous';
12
- const escalationQueueName = `escalate-${brokerSafeId(id)}-${brokerSafeId(escalationId)}-q`;
13
-
14
- if (!isThrowing) setupCatch();
15
-
16
- const source = {
17
- id,
18
- type,
19
- reference: {...reference, referenceType: 'escalate'},
20
- execute: isThrowing ? executeThrow : executeCatch,
14
+
15
+ this.id = id;
16
+ this.type = type;
17
+
18
+ const reference = this.reference = {
19
+ name: 'anonymous',
20
+ ...behaviour.escalationRef,
21
+ referenceType: 'escalate',
21
22
  };
22
23
 
23
- return source;
24
+ this.isThrowing = isThrowing;
25
+ this.activity = activity;
26
+ this.broker = broker;
27
+ this.logger = environment.Logger(type.toLowerCase());
28
+
29
+ const referenceElement = this[referenceElementSymbol] = reference.id && activity.getActivityById(reference.id);
30
+ if (!isThrowing) {
31
+ this[completedSymbol] = false;
32
+ const referenceId = referenceElement ? referenceElement.id : 'anonymous';
33
+ const messageQueueName = `${reference.referenceType}-${brokerSafeId(id)}-${brokerSafeId(referenceId)}-q`;
34
+ this[messageQSymbol] = broker.assertQueue(messageQueueName, {autoDelete: false, durable: true});
35
+ broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, {durable: true, priority: 400});
36
+ }
37
+ }
24
38
 
25
- function executeCatch(executeMessage) {
26
- let completed;
39
+ const proto = EscalationEventDefinition.prototype;
27
40
 
28
- const messageContent = cloneContent(executeMessage.content);
29
- const {executionId, parent} = messageContent;
30
- const parentExecutionId = parent && parent.executionId;
41
+ Object.defineProperty(proto, 'executionId', {
42
+ get() {
43
+ const message = this[executeMessageSymbol];
44
+ return message && message.content.executionId;
45
+ },
46
+ });
31
47
 
32
- const {message: referenceMessage, description} = resolveMessage(executeMessage);
33
- broker.consume(escalationQueueName, onEscalationApiMessage, {noAck: true, consumerTag: `_onescalate-${executionId}`});
48
+ proto.execute = function execute(executeMessage) {
49
+ return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
50
+ };
34
51
 
35
- if (completed) return;
52
+ proto.executeCatch = function executeCatch(executeMessage) {
53
+ this[executeMessageSymbol] = executeMessage;
54
+ this[completedSymbol] = false;
36
55
 
37
- broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {noAck: true, consumerTag: `_api-${executionId}`});
56
+ const executeContent = executeMessage.content;
57
+ const {executionId, parent} = executeContent;
38
58
 
39
- if (completed) return stop();
59
+ const info = this[referenceInfoSymbol] = this._getReferenceInfo(executeMessage);
60
+ const broker = this.broker;
61
+ this[messageQSymbol].consume(this._onCatchMessage.bind(this), {
62
+ noAck: true,
63
+ consumerTag: `_onescalate-${executionId}`,
64
+ });
40
65
 
41
- debug(`<${executionId} (${id})> expect ${description}`);
66
+ if (this[completedSymbol]) return;
42
67
 
43
- broker.publish('event', 'activity.wait', {
44
- ...messageContent,
45
- executionId: parentExecutionId,
46
- parent: shiftParent(parent),
47
- escalation: {...referenceMessage},
48
- });
68
+ broker.subscribeTmp('api', `activity.#.${executionId}`, this._onApiMessage.bind(this), {
69
+ noAck: true,
70
+ consumerTag: `_api-${executionId}`,
71
+ });
49
72
 
50
- function onEscalationApiMessage(routingKey, message) {
51
- if (getPropertyValue(message, 'content.message.id') !== referenceMessage.id) return;
73
+ this._debug(`expect ${info.description}`);
52
74
 
53
- const output = message.content.message;
54
- completed = true;
75
+ const waitContent = cloneContent(executeContent, {
76
+ executionId: parent.executionId,
77
+ parent: shiftParent(parent),
78
+ escalation: {...info.message},
79
+ });
80
+ waitContent.parent = shiftParent(parent);
55
81
 
56
- stop();
82
+ broker.publish('event', 'activity.wait', waitContent);
83
+ };
57
84
 
58
- debug(`<${executionId} (${id})> caught ${description}`);
59
- broker.publish('event', 'activity.catch', {
60
- ...messageContent,
61
- message: {...output},
62
- executionId: parentExecutionId,
63
- parent: shiftParent(executeMessage.content.parent),
64
- }, {type: 'catch'});
85
+ proto.executeThrow = function executeThrow(executeMessage) {
86
+ const executeContent = executeMessage.content;
87
+ const {executionId, parent} = executeContent;
65
88
 
66
- return broker.publish('execution', 'execute.completed', {...messageContent, output, state: 'catch'});
67
- }
89
+ const info = this._getReferenceInfo(executeMessage);
90
+ this.logger.debug(`<${executionId} (${this.activity.id})> escalate ${info.description}`);
68
91
 
69
- function onApiMessage(routingKey, message) {
70
- const messageType = message.properties.type;
71
-
72
- switch (messageType) {
73
- case 'escalate': {
74
- return onEscalationApiMessage(routingKey, message);
75
- }
76
- case 'discard': {
77
- completed = true;
78
- stop();
79
- return broker.publish('execution', 'execute.discard', {...messageContent});
80
- }
81
- case 'stop': {
82
- stop();
83
- break;
84
- }
85
- }
86
- }
92
+ const broker = this.broker;
93
+ const throwContent = cloneContent(executeContent, {
94
+ executionId: parent.executionId,
95
+ message: info.message,
96
+ state: 'throw',
97
+ });
98
+ throwContent.parent = shiftParent(parent);
87
99
 
88
- function stop() {
89
- broker.cancel(`_api-${executionId}`);
90
- broker.cancel(`_onescalate-${executionId}`);
91
- }
92
- }
100
+ broker.publish('event', 'activity.escalate', throwContent, {type: 'escalate', delegate: true});
93
101
 
94
- function executeThrow(executeMessage) {
95
- const messageContent = cloneContent(executeMessage.content);
96
- const {executionId, parent} = messageContent;
97
- const parentExecutionId = parent && parent.executionId;
102
+ return broker.publish('execution', 'execute.completed', cloneContent(executeContent));
103
+ };
98
104
 
99
- const {message: referenceMessage, description} = resolveMessage(executeMessage);
105
+ proto._onCatchMessage = function onCatchMessage(routingKey, message) {
106
+ const info = this[referenceInfoSymbol];
107
+ if (getPropertyValue(message, 'content.message.id') !== info.message.id) return;
100
108
 
101
- debug(`<${executionId} (${id})> escalate ${description}`);
109
+ const output = message.content.message;
110
+ this[completedSymbol] = true;
102
111
 
103
- broker.publish('event', 'activity.escalate', {
104
- ...cloneContent(messageContent),
105
- executionId: parentExecutionId,
106
- parent: shiftParent(parent),
107
- message: {...referenceMessage},
108
- state: 'throw',
109
- }, {type: 'escalate', delegate: true});
112
+ this._stop();
110
113
 
111
- return broker.publish('execution', 'execute.completed', {...messageContent});
112
- }
114
+ this._debug(`caught ${info.description}`);
113
115
 
114
- function resolveMessage(message) {
115
- if (!referenceElement) {
116
- return {
117
- message: {...reference},
118
- description: 'anonymous escalation',
119
- };
120
- }
116
+ const executeContent = this[executeMessageSymbol].content;
117
+ const {parent, ...content} = executeContent;
118
+ const catchContent = cloneContent(content, {
119
+ message: {...output},
120
+ executionId: parent.executionId,
121
+ });
122
+ catchContent.parent = shiftParent(parent);
121
123
 
122
- const result = {
123
- message: referenceElement.resolve(message),
124
- };
124
+ const broker = this.broker;
125
+ broker.publish('event', 'activity.catch', catchContent, {type: 'catch'});
125
126
 
126
- result.description = `${result.message.name} <${result.message.id}>`;
127
+ return broker.publish('execution', 'execute.completed', cloneContent(executeContent, {output, state: 'catch'}));
128
+ };
127
129
 
128
- return result;
130
+ proto._onApiMessage = function onApiMessage(routingKey, message) {
131
+ switch (message.properties.type) {
132
+ case 'escalate': {
133
+ return this._onCatchMessage(routingKey, message);
134
+ }
135
+ case 'discard': {
136
+ this[completedSymbol] = true;
137
+ this._stop();
138
+ return this.broker.publish('execution', 'execute.discard', cloneContent(this[executeMessageSymbol].content));
139
+ }
140
+ case 'stop': {
141
+ this._stop();
142
+ break;
143
+ }
129
144
  }
130
-
131
- function setupCatch() {
132
- broker.assertQueue(escalationQueueName, {autoDelete: false, durable: true});
133
- broker.bindQueue(escalationQueueName, 'api', '*.escalate.#', {durable: true, priority: 400});
145
+ };
146
+
147
+ proto._stop = function stop() {
148
+ const broker = this.broker, executionId = this.executionId;
149
+ broker.cancel(`_api-${executionId}`);
150
+ broker.cancel(`_onescalate-${executionId}`);
151
+ };
152
+
153
+ proto._getReferenceInfo = function getReferenceInfo(message) {
154
+ const referenceElement = this[referenceElementSymbol];
155
+ if (!referenceElement) {
156
+ return {
157
+ message: {...this.reference},
158
+ description: 'anonymous escalation',
159
+ };
134
160
  }
135
- }
161
+
162
+ const result = {
163
+ message: referenceElement.resolve(message),
164
+ };
165
+
166
+ result.description = `${result.message.name} <${result.message.id}>`;
167
+
168
+ return result;
169
+ };
170
+
171
+ proto._debug = function debug(msg) {
172
+ this.logger.debug(`<${this.executionId} (${this.activity.id})> ${msg}`);
173
+ };
@@ -1,113 +1,145 @@
1
- import {cloneContent, unshiftParent, shiftParent} from '../messageHelper';
1
+ import {cloneContent, unshiftParent, shiftParent, cloneParent} from '../messageHelper';
2
+
3
+ const completedSymbol = Symbol.for('completed');
4
+ const executeMessageSymbol = Symbol.for('executeMessage');
5
+ const stoppedSymbol = Symbol.for('stopped');
2
6
 
3
7
  export default function EventDefinitionExecution(activity, eventDefinitions, completedRoutingKey = 'execute.completed') {
4
- const {id, broker, logger} = activity;
5
- const executeConsumerTag = '_eventdefinition-execution-execute-tag';
6
- const apiConsumerTag = '_eventdefinition-execution-api-tag';
8
+ this.id = activity.id;
9
+ this.activity = activity;
10
+ this.broker = activity.broker;
11
+ this.eventDefinitions = eventDefinitions;
12
+ this.completedRoutingKey = completedRoutingKey;
13
+ this[completedSymbol] = false;
14
+ this[stoppedSymbol] = false;
15
+ this[executeMessageSymbol] = null;
16
+ }
7
17
 
8
- let parentExecutionContent, parent, completed = false, stopped = false;
18
+ const proto = EventDefinitionExecution.prototype;
9
19
 
10
- return {
11
- execute,
12
- get completed() {
13
- return completed;
14
- },
15
- };
20
+ Object.defineProperty(proto, 'completed', {
21
+ enumerable: true,
22
+ get() {
23
+ return this[completedSymbol];
24
+ },
25
+ });
16
26
 
17
- function execute(executeMessage) {
18
- const executeContent = executeMessage.content;
19
- const isRedelivered = executeMessage.fields.redelivered;
20
- const {isRootScope, isDefinitionScope, executionId: messageExecutionId} = executeContent;
27
+ Object.defineProperty(proto, 'stopped', {
28
+ enumerable: true,
29
+ get() {
30
+ return this[stoppedSymbol];
31
+ },
32
+ });
21
33
 
22
- if (isDefinitionScope) return executeDefinition();
34
+ proto.execute = function execute(executeMessage) {
35
+ const content = executeMessage.content;
23
36
 
24
- let parentExecutionId;
25
- if (isRootScope) {
26
- parentExecutionId = messageExecutionId;
27
- parentExecutionContent = executeContent;
37
+ if (content.isDefinitionScope) return this._executeDefinition(executeMessage);
38
+ if (!content.isRootScope) return;
28
39
 
29
- broker.subscribeTmp('execution', 'execute.#', onExecuteMessage, {noAck: true, consumerTag: executeConsumerTag, priority: 300});
30
- broker.subscribeTmp('api', `activity.*.${parentExecutionId}`, onApiMessage, {noAck: true, consumerTag: apiConsumerTag, priority: 300});
40
+ const broker = this.broker;
31
41
 
32
- parent = unshiftParent(parentExecutionContent.parent, parentExecutionContent);
33
- broker.publish('execution', 'execute.update', {...cloneContent(parentExecutionContent), preventComplete: true});
34
- }
35
- if (isRedelivered) return;
36
-
37
- for (let index = 0; index < eventDefinitions.length; ++index) {
38
- if (completed) break;
39
- if (stopped) break;
40
-
41
- const ed = eventDefinitions[index];
42
- const executionId = `${messageExecutionId}_${index}`;
43
-
44
- logger.debug(`<${messageExecutionId} (${id})> start event definition ${ed.type}, index ${index}`);
45
-
46
- broker.publish('execution', 'execute.start', {
47
- ...cloneContent(parentExecutionContent),
48
- isRootScope: undefined,
49
- type: ed.type,
50
- executionId,
51
- isDefinitionScope: true,
52
- index,
53
- parent,
54
- });
55
- }
42
+ this[executeMessageSymbol] = executeMessage;
43
+ const executionId = content.executionId;
56
44
 
57
- function onApiMessage(_, message) {
58
- const messageType = message.properties.type;
59
- switch (messageType) {
60
- case 'stop':
61
- stopped = true;
62
- case 'discard':
63
- return stop();
64
- }
65
- }
45
+ broker.subscribeTmp('execution', 'execute.#', this._onExecuteMessage.bind(this), {
46
+ noAck: true,
47
+ consumerTag: '_eventdefinition-execution-execute-tag',
48
+ priority: 300,
49
+ });
50
+ broker.subscribeTmp('api', `activity.*.${executionId}`, this._onApiMessage.bind(this), {
51
+ noAck: true,
52
+ consumerTag: '_eventdefinition-execution-api-tag',
53
+ priority: 300,
54
+ });
66
55
 
67
- function onExecuteMessage(routingKey, message) {
68
- const {correlationId} = message.properties;
69
- switch (routingKey) {
70
- case 'execute.completed': {
71
- stop();
72
- if (message.content.isDefinitionScope) return complete();
73
- break;
74
- }
75
- case 'execute.discard': {
76
- if (message.content.isDefinitionScope) {
77
- logger.debug(`<${message.content.executionId} (${id})> event definition ${message.content.type} discarded, index ${message.content.index}`);
78
- break;
79
- }
80
- stop();
81
- logger.debug(`<${message.content.executionId} (${id})> event definition parent execution discarded`);
82
- break;
83
- }
84
- }
56
+ broker.publish('execution', 'execute.update', cloneContent(content, {preventComplete: true}));
85
57
 
86
- function complete() {
87
- const content = cloneContent(message.content);
88
- completed = true;
58
+ if (executeMessage.fields.redelivered) return;
89
59
 
90
- logger.debug(`<${content.executionId} (${id})> event definition ${content.type} completed, index ${content.index}`);
60
+ const parent = unshiftParent(content.parent, content);
61
+ const eventDefinitions = this.eventDefinitions;
91
62
 
92
- broker.publish('execution', completedRoutingKey, {
93
- ...cloneContent(content),
94
- executionId: parentExecutionId,
95
- isRootScope: true,
96
- parent: shiftParent(content.parent),
97
- }, {correlationId});
98
- }
99
- }
63
+ for (let index = 0; index < eventDefinitions.length; ++index) {
64
+ if (this[completedSymbol]) break;
65
+ if (this[stoppedSymbol]) break;
100
66
 
101
- function executeDefinition() {
102
- const ed = eventDefinitions[executeContent.index];
103
- if (!ed) return logger.warn(`<${messageExecutionId} (${id})> found no event definition on index ${executeContent.index}`);
104
- logger.debug(`<${messageExecutionId} (${id})> execute event definition ${ed.type}, index ${executeContent.index}`);
105
- ed.execute(executeMessage);
106
- }
67
+ const ed = eventDefinitions[index];
68
+ const edExecutionId = `${executionId}_${index}`;
69
+
70
+ this._debug(executionId, `start event definition ${ed.type}, index ${index}`);
107
71
 
108
- function stop() {
109
- broker.cancel(executeConsumerTag);
110
- broker.cancel(apiConsumerTag);
72
+ const edContent = cloneContent(content, {
73
+ isRootScope: undefined,
74
+ type: ed.type,
75
+ executionId: edExecutionId,
76
+ isDefinitionScope: true,
77
+ index,
78
+ });
79
+ edContent.parent = cloneParent(parent);
80
+
81
+ broker.publish('execution', 'execute.start', edContent);
82
+ }
83
+ };
84
+
85
+ proto._onApiMessage = function onApiMessage(_, message) {
86
+ const messageType = message.properties.type;
87
+ switch (messageType) {
88
+ case 'stop':
89
+ case 'discard':
90
+ return this._stop();
91
+ }
92
+ };
93
+
94
+ proto._onExecuteMessage = function onExecuteMessage(routingKey, message) {
95
+ switch (routingKey) {
96
+ case 'execute.completed': {
97
+ this._stop();
98
+ if (message.content.isDefinitionScope) return this._complete(message);
99
+ break;
100
+ }
101
+ case 'execute.discard': {
102
+ const {executionId, isDefinitionScope} = message.content;
103
+ if (isDefinitionScope) {
104
+ this._debug(executionId, `event definition ${message.content.type} discarded, index ${message.content.index}`);
105
+ break;
106
+ }
107
+ this._stop();
108
+ this._debug(executionId, 'event definition parent execution discarded');
109
+ break;
111
110
  }
112
111
  }
113
- }
112
+ };
113
+
114
+ proto._complete = function complete(message) {
115
+ const {executionId, type, index, parent} = message.content;
116
+ this[completedSymbol] = true;
117
+
118
+ this._debug(executionId, `event definition ${type} completed, index ${index}`);
119
+
120
+ const completeContent = cloneContent(message.content, {
121
+ executionId: this[executeMessageSymbol].content.executionId,
122
+ isRootScope: true,
123
+ });
124
+ completeContent.parent = shiftParent(parent);
125
+
126
+ this.broker.publish('execution', this.completedRoutingKey, completeContent, {correlationId: message.properties.correlationId});
127
+ };
128
+
129
+ proto._executeDefinition = function executeDefinition(message) {
130
+ const {executionId, index} = message.content;
131
+ const ed = this.eventDefinitions[index];
132
+ if (!ed) return this.activity.logger.warn(`<${executionId} (${this.id})> found no event definition on index ${index}`);
133
+ this._debug(executionId, `execute event definition ${ed.type}, index ${index}`);
134
+ ed.execute(message);
135
+ };
136
+
137
+ proto._stop = function stop() {
138
+ this[stoppedSymbol] = true;
139
+ this.broker.cancel('_eventdefinition-execution-execute-tag');
140
+ this.broker.cancel('_eventdefinition-execution-api-tag');
141
+ };
142
+
143
+ proto._debug = function debug(executionId, msg) {
144
+ this.activity.logger.debug(`<${executionId} (${this.id})> ${msg}`);
145
+ };