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
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = SequenceFlow;
6
+ exports.default = void 0;
7
7
 
8
8
  var _ExecutionScope = _interopRequireDefault(require("../activity/ExecutionScope"));
9
9
 
@@ -17,6 +17,10 @@ var _Api = require("../Api");
17
17
 
18
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
19
 
20
+ const countersSymbol = Symbol.for('counters');
21
+ var _default = SequenceFlow;
22
+ exports.default = _default;
23
+
20
24
  function SequenceFlow(flowDef, {
21
25
  environment
22
26
  }) {
@@ -24,233 +28,217 @@ function SequenceFlow(flowDef, {
24
28
  id,
25
29
  type = 'sequenceflow',
26
30
  name,
27
- parent: originalParent,
31
+ parent,
28
32
  targetId,
29
33
  sourceId,
30
34
  isDefault,
31
35
  behaviour = {}
32
36
  } = flowDef;
33
- const parent = (0, _messageHelper.cloneParent)(originalParent);
34
- const logger = environment.Logger(type.toLowerCase());
35
- const flowBase = {
36
- id,
37
- type,
38
- name,
39
- parent,
40
- behaviour,
41
- sourceId,
42
- targetId,
43
- isDefault,
44
- isSequenceFlow: true,
45
- environment,
46
- logger
47
- };
48
- environment.registerScript({ ...flowBase
49
- });
50
- let counters = {
37
+ this.id = id;
38
+ this.type = type;
39
+ this.name = name;
40
+ this.parent = (0, _messageHelper.cloneParent)(parent);
41
+ this.behaviour = behaviour;
42
+ this.sourceId = sourceId;
43
+ this.targetId = targetId;
44
+ this.isDefault = isDefault;
45
+ this.isSequenceFlow = true;
46
+ this.environment = environment;
47
+ const logger = this.logger = environment.Logger(type.toLowerCase());
48
+ this[countersSymbol] = {
51
49
  looped: 0,
52
50
  take: 0,
53
51
  discard: 0
54
52
  };
55
- const flowApi = { ...flowBase,
56
-
57
- get counters() {
58
- return { ...counters
59
- };
60
- },
61
-
62
- discard,
63
- evaluateCondition,
64
- getApi,
65
- getCondition,
66
- getState,
67
- recover,
68
- shake,
69
- stop,
70
- take
71
- };
53
+ environment.registerScript(this);
72
54
  const {
73
55
  broker,
74
56
  on,
75
57
  once,
76
58
  waitFor,
77
59
  emitFatal
78
- } = (0, _EventBroker.EventBroker)(flowApi, {
60
+ } = new _EventBroker.EventBroker(this, {
79
61
  prefix: 'flow',
80
62
  durable: true,
81
63
  autoDelete: false
82
64
  });
83
- flowApi.on = on;
84
- flowApi.once = once;
85
- flowApi.waitFor = waitFor;
86
- Object.defineProperty(flowApi, 'broker', {
87
- enumerable: true,
88
- get: () => broker
89
- });
65
+ this.broker = broker;
66
+ this.on = on;
67
+ this.once = once;
68
+ this.waitFor = waitFor;
69
+ this.emitFatal = emitFatal;
90
70
  logger.debug(`<${id}> init, <${sourceId}> -> <${targetId}>`);
91
- return flowApi;
92
-
93
- function take(content = {}) {
94
- flowApi.looped = undefined;
95
- const {
96
- sequenceId
97
- } = content;
98
- logger.debug(`<${sequenceId} (${id})> take, target <${targetId}>`);
99
- ++counters.take;
100
- publishEvent('take', content);
101
- return true;
102
- }
71
+ }
103
72
 
104
- function discard(content = {}) {
105
- const {
106
- sequenceId = (0, _shared.getUniqueId)(id)
107
- } = content;
108
- const discardSequence = content.discardSequence = (content.discardSequence || []).slice();
109
-
110
- if (discardSequence.indexOf(targetId) > -1) {
111
- ++counters.looped;
112
- logger.debug(`<${id}> discard loop detected <${sourceId}> -> <${targetId}>. Stop.`);
113
- return publishEvent('looped', content);
114
- }
115
-
116
- discardSequence.push(sourceId);
117
- logger.debug(`<${sequenceId} (${id})> discard, target <${targetId}>`);
118
- ++counters.discard;
119
- publishEvent('discard', content);
120
- }
73
+ const proto = SequenceFlow.prototype;
74
+ Object.defineProperty(proto, 'counters', {
75
+ enumerable: true,
121
76
 
122
- function publishEvent(action, content) {
123
- const eventContent = createMessage({
124
- action,
125
- ...content
126
- });
127
- broker.publish('event', `flow.${action}`, eventContent, {
128
- type: action
129
- });
130
- }
131
-
132
- function createMessage(override) {
133
- return { ...override,
134
- id,
135
- type,
136
- name,
137
- sourceId,
138
- targetId,
139
- isSequenceFlow: true,
140
- isDefault,
141
- parent: (0, _messageHelper.cloneParent)(parent)
77
+ get() {
78
+ return { ...this[countersSymbol]
142
79
  };
143
80
  }
144
81
 
145
- function getState() {
146
- const result = {
147
- id,
148
- type,
149
- name,
150
- sourceId,
151
- targetId,
152
- isDefault,
153
- counters: { ...counters
154
- }
155
- };
156
- result.broker = broker.getState();
157
- return result;
158
- }
82
+ });
159
83
 
160
- function recover(state) {
161
- counters = { ...counters,
162
- ...state.counters
163
- };
164
- broker.recover(state.broker);
165
- }
84
+ proto.take = function take(content = {}) {
85
+ this.looped = undefined;
86
+ const {
87
+ sequenceId
88
+ } = content;
89
+ this.logger.debug(`<${sequenceId} (${this.id})> take, target <${this.targetId}>`);
90
+ ++this[countersSymbol].take;
166
91
 
167
- function getApi(message) {
168
- return (0, _Api.FlowApi)(broker, message || {
169
- content: createMessage()
170
- });
171
- }
92
+ this._publishEvent('take', content);
172
93
 
173
- function stop() {
174
- broker.stop();
94
+ return true;
95
+ };
96
+
97
+ proto.discard = function discard(content = {}) {
98
+ const {
99
+ sequenceId = (0, _shared.getUniqueId)(this.id)
100
+ } = content;
101
+ const discardSequence = content.discardSequence = (content.discardSequence || []).slice();
102
+
103
+ if (discardSequence.indexOf(this.targetId) > -1) {
104
+ ++this[countersSymbol].looped;
105
+ this.logger.debug(`<${this.id}> discard loop detected <${this.sourceId}> -> <${this.targetId}>. Stop.`);
106
+ return this._publishEvent('looped', content);
175
107
  }
176
108
 
177
- function shake(message) {
178
- const content = (0, _messageHelper.cloneContent)(message.content);
179
- content.sequence = content.sequence || [];
180
- content.sequence.push({
181
- id,
182
- type,
183
- isSequenceFlow: true,
184
- targetId
185
- });
186
- if (content.id === targetId) return broker.publish('event', 'flow.shake.loop', content, {
187
- persistent: false,
188
- type: 'shake'
189
- });
109
+ discardSequence.push(this.sourceId);
110
+ this.logger.debug(`<${sequenceId} (${this.id})> discard, target <${this.targetId}>`);
111
+ ++this[countersSymbol].discard;
112
+
113
+ this._publishEvent('discard', content);
114
+ };
190
115
 
191
- for (const s of message.content.sequence) {
192
- if (s.id === id) return broker.publish('event', 'flow.shake.loop', content, {
193
- persistent: false,
194
- type: 'shake'
195
- });
196
- }
116
+ proto.getState = function getState() {
117
+ return this.createMessage({
118
+ counters: this.counters,
119
+ broker: this.broker.getState(true)
120
+ });
121
+ };
122
+
123
+ proto.recover = function recover(state) {
124
+ Object.assign(this[countersSymbol], state.counters);
125
+ this.broker.recover(state.broker);
126
+ };
127
+
128
+ proto.getApi = function getApi(message) {
129
+ return (0, _Api.FlowApi)(this.broker, message || {
130
+ content: this.createMessage()
131
+ });
132
+ };
133
+
134
+ proto.stop = function stop() {
135
+ this.broker.stop();
136
+ };
137
+
138
+ proto.shake = function shake(message) {
139
+ const content = (0, _messageHelper.cloneContent)(message.content);
140
+ content.sequence = content.sequence || [];
141
+ content.sequence.push({
142
+ id: this.id,
143
+ type: this.type,
144
+ isSequenceFlow: true,
145
+ targetId: this.targetId
146
+ });
147
+ if (content.id === this.targetId) return this.broker.publish('event', 'flow.shake.loop', content, {
148
+ persistent: false,
149
+ type: 'shake'
150
+ });
197
151
 
198
- broker.publish('event', 'flow.shake', content, {
152
+ for (const s of message.content.sequence) {
153
+ if (s.id === this.id) return this.broker.publish('event', 'flow.shake.loop', content, {
199
154
  persistent: false,
200
155
  type: 'shake'
201
156
  });
202
157
  }
203
158
 
204
- function evaluateCondition(message, callback) {
205
- const condition = getCondition(message);
206
- if (!condition) return callback(null, true);
207
- return condition.execute(message, callback);
208
- }
209
-
210
- function getCondition() {
211
- const conditionExpression = behaviour.conditionExpression;
212
- if (!conditionExpression) return null;
213
- const {
214
- language
215
- } = conditionExpression;
216
- const script = environment.getScript(language, flowApi);
159
+ this.broker.publish('event', 'flow.shake', content, {
160
+ persistent: false,
161
+ type: 'shake'
162
+ });
163
+ };
217
164
 
218
- if (script) {
219
- return ScriptCondition(script, language);
220
- }
165
+ proto.getCondition = function getCondition() {
166
+ const conditionExpression = this.behaviour.conditionExpression;
167
+ if (!conditionExpression) return null;
168
+ const {
169
+ language
170
+ } = conditionExpression;
171
+ const script = this.environment.getScript(language, this);
221
172
 
222
- if (!conditionExpression.body) {
223
- const msg = language ? `Condition expression script ${language} is unsupported or was not registered` : 'Condition expression without body is unsupported';
224
- return emitFatal(new Error(msg), createMessage());
225
- }
173
+ if (script) {
174
+ return new ScriptCondition(this, script, language);
175
+ }
226
176
 
227
- return ExpressionCondition(conditionExpression.body);
177
+ if (!conditionExpression.body) {
178
+ const msg = language ? `Condition expression script ${language} is unsupported or was not registered` : 'Condition expression without body is unsupported';
179
+ return this.emitFatal(new Error(msg), this.createMessage());
228
180
  }
229
181
 
230
- function ScriptCondition(script, language) {
231
- return {
232
- language,
182
+ return new ExpressionCondition(this, conditionExpression.body);
183
+ };
233
184
 
234
- execute(message, callback) {
235
- try {
236
- return script.execute((0, _ExecutionScope.default)(flowApi, message), callback);
237
- } catch (err) {
238
- if (!callback) throw err;
239
- logger.error(`<${id}>`, err);
240
- callback(err);
241
- }
242
- }
185
+ proto.createMessage = function createMessage(override) {
186
+ return { ...override,
187
+ id: this.id,
188
+ type: this.type,
189
+ name: this.name,
190
+ sourceId: this.sourceId,
191
+ targetId: this.targetId,
192
+ isSequenceFlow: true,
193
+ isDefault: this.isDefault,
194
+ parent: (0, _messageHelper.cloneParent)(this.parent)
195
+ };
196
+ };
243
197
 
244
- };
198
+ proto._publishEvent = function publishEvent(action, content) {
199
+ const eventContent = this.createMessage({
200
+ action,
201
+ ...content
202
+ });
203
+ this.broker.publish('event', `flow.${action}`, eventContent, {
204
+ type: action
205
+ });
206
+ };
207
+
208
+ function ScriptCondition(owner, script, language) {
209
+ this.type = 'script';
210
+ this.language = language;
211
+ this._owner = owner;
212
+ this._script = script;
213
+ }
214
+
215
+ ScriptCondition.prototype.execute = function execute(message, callback) {
216
+ const owner = this._owner;
217
+
218
+ try {
219
+ return this._script.execute((0, _ExecutionScope.default)(owner, message), callback);
220
+ } catch (err) {
221
+ if (!callback) throw err;
222
+ owner.logger.error(`<${owner.id}>`, err);
223
+ callback(err);
245
224
  }
225
+ };
246
226
 
247
- function ExpressionCondition(expression) {
248
- return {
249
- execute: (message, callback) => {
250
- const result = environment.resolveExpression(expression, createMessage(message));
251
- if (callback) return callback(null, result);
252
- return result;
253
- }
254
- };
227
+ function ExpressionCondition(owner, expression) {
228
+ this.type = 'expression';
229
+ this.expression = expression;
230
+ this._owner = owner;
231
+ }
232
+
233
+ ExpressionCondition.prototype.execute = function execute(message, callback) {
234
+ const owner = this._owner;
235
+
236
+ try {
237
+ const result = owner.environment.resolveExpression(this.expression, owner.createMessage(message));
238
+ if (callback) return callback(null, result);
239
+ return result;
240
+ } catch (err) {
241
+ if (callback) return callback(err);
242
+ throw err;
255
243
  }
256
- }
244
+ };
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = EventBasedGateway;
7
6
  exports.EventBasedGatewayBehaviour = EventBasedGatewayBehaviour;
7
+ exports.default = EventBasedGateway;
8
8
 
9
9
  var _Activity = _interopRequireDefault(require("../activity/Activity"));
10
10
 
@@ -12,94 +12,98 @@ var _messageHelper = require("../messageHelper");
12
12
 
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
14
 
15
+ const completedSymbol = Symbol.for('completed');
16
+ const targetsSymbol = Symbol.for('targets');
17
+
15
18
  function EventBasedGateway(activityDef, context) {
16
- return (0, _Activity.default)(EventBasedGatewayBehaviour, { ...activityDef
17
- }, context);
19
+ return new _Activity.default(EventBasedGatewayBehaviour, activityDef, context);
18
20
  }
19
21
 
20
22
  function EventBasedGatewayBehaviour(activity, context) {
23
+ this.id = activity.id;
24
+ this.type = activity.type;
25
+ this.activity = activity;
26
+ this.broker = activity.broker;
27
+ this.context = context;
28
+ this[targetsSymbol] = activity.outbound.map(flow => context.getActivityById(flow.targetId));
29
+ }
30
+
31
+ EventBasedGatewayBehaviour.prototype.execute = function execute(executeMessage) {
32
+ const executeContent = executeMessage.content;
21
33
  const {
22
- id,
23
- type,
24
- broker,
25
- logger,
26
- outbound: outboundSequenceFlows = []
27
- } = activity;
28
- let executing = false;
29
- const source = {
30
- id,
31
- type,
32
- execute
33
- };
34
- return source;
35
-
36
- function execute(executeMessage) {
37
- const isRedelivered = executeMessage.fields.redelivered;
38
- const content = executeMessage.content;
39
- const {
40
- executionId,
41
- outbound = [],
42
- outboundTaken
43
- } = content;
44
- const targets = [];
45
-
46
- for (let i = 0; i < outboundSequenceFlows.length; i++) {
47
- const flow = outboundSequenceFlows[i];
48
- targets.push(context.getActivityById(flow.targetId));
49
- outbound.push({
50
- id: flow.id,
51
- action: 'take'
52
- });
53
- }
54
-
55
- if (!targets.length) return complete(content);
56
- if (executing && outboundTaken) return;
57
- const targetConsumerTag = `_gateway-listener-${id}`;
58
- targets.forEach(target => {
59
- target.broker.subscribeOnce('event', 'activity.end', onTargetCompleted, {
60
- consumerTag: targetConsumerTag
61
- });
34
+ executionId,
35
+ outbound = [],
36
+ outboundTaken
37
+ } = executeContent;
38
+ const targets = this[targetsSymbol];
39
+ this[completedSymbol] = false;
40
+ if (!targets.length) return this._complete(executeContent);
41
+
42
+ for (const flow of this.activity.outbound) {
43
+ outbound.push({
44
+ id: flow.id,
45
+ action: 'take'
62
46
  });
63
- broker.subscribeOnce('api', `activity.stop.${executionId}`, stop, {
64
- noAck: true,
65
- consumerTag: `_api-stop-${executionId}`
47
+ }
48
+
49
+ if (!this[completedSymbol] && outboundTaken) return;
50
+ const targetConsumerTag = `_gateway-listener-${this.id}`;
51
+
52
+ const onTargetCompleted = this._onTargetCompleted.bind(this, executeMessage);
53
+
54
+ for (const target of this[targetsSymbol]) {
55
+ target.broker.subscribeOnce('event', 'activity.end', onTargetCompleted, {
56
+ consumerTag: targetConsumerTag
66
57
  });
67
- executing = true;
68
- if (!isRedelivered) return broker.publish('execution', 'execute.outbound.take', (0, _messageHelper.cloneContent)(content, {
69
- outboundTaken: true
70
- }));
71
-
72
- function onTargetCompleted(_, message, owner) {
73
- const {
74
- id: targetId,
75
- exexutionId: targetExecutionId
76
- } = message.content;
77
- logger.debug(`<${executionId} (${id})> <${targetExecutionId}> completed run, discarding the rest`);
78
- targets.forEach(target => {
79
- if (target === owner) return;
80
- target.broker.cancel(targetConsumerTag);
81
- target.discard();
82
- });
83
- const completedContent = (0, _messageHelper.cloneContent)(executeMessage.content, {
84
- taken: {
85
- id: targetId,
86
- executionId: targetExecutionId
87
- },
88
- ignoreOutbound: true
89
- });
90
- complete(completedContent);
91
- }
92
-
93
- function complete(completedContent) {
94
- broker.publish('execution', 'execute.completed', completedContent);
95
- }
96
-
97
- function stop() {
98
- executing = false;
99
- targets.forEach(target => {
100
- target.broker.cancel(targetConsumerTag);
101
- });
102
- broker.cancel(`_api-stop-${executionId}`);
103
- }
104
58
  }
105
- }
59
+
60
+ const broker = this.activity.broker;
61
+ broker.subscribeOnce('api', `activity.stop.${executionId}`, () => this._stop(), {
62
+ noAck: true,
63
+ consumerTag: '_api-stop-execution'
64
+ });
65
+ this[completedSymbol] = false;
66
+ if (!executeMessage.fields.redelivered) return broker.publish('execution', 'execute.outbound.take', (0, _messageHelper.cloneContent)(executeContent, {
67
+ outboundTaken: true
68
+ }));
69
+ };
70
+
71
+ EventBasedGatewayBehaviour.prototype._onTargetCompleted = function onTargetCompleted(executeMessage, _, message, owner) {
72
+ const {
73
+ id: targetId,
74
+ exexutionId: targetExecutionId
75
+ } = message.content;
76
+ const executeContent = executeMessage.content;
77
+ const executionId = executeContent.executionId;
78
+ this.activity.logger.debug(`<${executionId} (${this.id})> <${targetExecutionId}> completed run, discarding the rest`);
79
+
80
+ this._stop();
81
+
82
+ for (const target of this[targetsSymbol]) {
83
+ if (target === owner) continue;
84
+ target.discard();
85
+ }
86
+
87
+ const completedContent = (0, _messageHelper.cloneContent)(executeContent, {
88
+ taken: {
89
+ id: targetId,
90
+ executionId: targetExecutionId
91
+ },
92
+ ignoreOutbound: true
93
+ });
94
+
95
+ this._complete(completedContent);
96
+ };
97
+
98
+ EventBasedGatewayBehaviour.prototype._complete = function complete(completedContent) {
99
+ this[completedSymbol] = true;
100
+ this.broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(completedContent));
101
+ };
102
+
103
+ EventBasedGatewayBehaviour.prototype._stop = function stop() {
104
+ const targetConsumerTag = `_gateway-listener-${this.id}`;
105
+
106
+ for (const target of this[targetsSymbol]) target.broker.cancel(targetConsumerTag);
107
+
108
+ this.broker.cancel('_api-stop-execution');
109
+ };
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = ExclusiveGateway;
7
6
  exports.ExclusiveGatewayBehaviour = ExclusiveGatewayBehaviour;
7
+ exports.default = ExclusiveGateway;
8
8
 
9
9
  var _Activity = _interopRequireDefault(require("../activity/Activity"));
10
10
 
@@ -13,7 +13,7 @@ var _messageHelper = require("../messageHelper");
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
14
 
15
15
  function ExclusiveGateway(activityDef, context) {
16
- return (0, _Activity.default)(ExclusiveGatewayBehaviour, activityDef, context);
16
+ return new _Activity.default(ExclusiveGatewayBehaviour, activityDef, context);
17
17
  }
18
18
 
19
19
  function ExclusiveGatewayBehaviour(activity) {
@@ -22,18 +22,15 @@ function ExclusiveGatewayBehaviour(activity) {
22
22
  type,
23
23
  broker
24
24
  } = activity;
25
- const source = {
26
- id,
27
- type,
28
- execute
29
- };
30
- return source;
25
+ this.id = id;
26
+ this.type = type;
27
+ this.broker = broker;
28
+ }
31
29
 
32
- function execute({
33
- content
34
- }) {
35
- broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(content, {
36
- outboundTakeOne: true
37
- }));
38
- }
39
- }
30
+ ExclusiveGatewayBehaviour.prototype.execute = function execute({
31
+ content
32
+ }) {
33
+ this.broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(content, {
34
+ outboundTakeOne: true
35
+ }));
36
+ };