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
@@ -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 kCompleted = Symbol.for('completed');
6
+ const kMessageQ = Symbol.for('messageQ');
7
+ const kExecuteMessage = Symbol.for('executeMessage');
8
+ const kReferenceElement = Symbol.for('referenceElement');
9
+ const kReference = 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[kReferenceElement] = reference.id && activity.getActivityById(reference.id);
30
+ if (!isThrowing) {
31
+ this[kCompleted] = false;
32
+ const referenceId = referenceElement ? referenceElement.id : 'anonymous';
33
+ const messageQueueName = `${reference.referenceType}-${brokerSafeId(id)}-${brokerSafeId(referenceId)}-q`;
34
+ this[kMessageQ] = 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[kExecuteMessage];
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[kExecuteMessage] = executeMessage;
54
+ this[kCompleted] = 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[kReference] = this._getReferenceInfo(executeMessage);
60
+ const broker = this.broker;
61
+ this[kMessageQ].consume(this._onCatchMessage.bind(this), {
62
+ noAck: true,
63
+ consumerTag: `_onescalate-${executionId}`,
64
+ });
40
65
 
41
- debug(`<${executionId} (${id})> expect ${description}`);
66
+ if (this[kCompleted]) 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[kReference];
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[kCompleted] = 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[kExecuteMessage].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[kCompleted] = true;
137
+ this._stop();
138
+ return this.broker.publish('execution', 'execute.discard', cloneContent(this[kExecuteMessage].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[kReferenceElement];
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 kCompleted = Symbol.for('completed');
4
+ const kExecuteMessage = Symbol.for('executeMessage');
5
+ const kStopped = 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[kCompleted] = false;
14
+ this[kStopped] = false;
15
+ this[kExecuteMessage] = 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[kCompleted];
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[kStopped];
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[kExecuteMessage] = 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[kCompleted]) break;
65
+ if (this[kStopped]) 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[kCompleted] = true;
117
+
118
+ this._debug(executionId, `event definition ${type} completed, index ${index}`);
119
+
120
+ const completeContent = cloneContent(message.content, {
121
+ executionId: this[kExecuteMessage].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[kStopped] = 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
+ };