bpmn-elements 6.0.0 → 8.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 +335 -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 +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 +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 +15 -15
  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 +915 -775
  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
@@ -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 kCounters = Symbol.for('counters');
21
+ var _default = SequenceFlow;
22
+ exports.default = _default;
23
+
20
24
  function SequenceFlow(flowDef, {
21
25
  environment
22
26
  }) {
@@ -24,230 +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[kCounters] = {
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
- getApi,
64
- getCondition,
65
- getState,
66
- recover,
67
- shake,
68
- stop,
69
- take
70
- };
53
+ environment.registerScript(this);
71
54
  const {
72
55
  broker,
73
56
  on,
74
57
  once,
75
58
  waitFor,
76
59
  emitFatal
77
- } = (0, _EventBroker.EventBroker)(flowApi, {
60
+ } = new _EventBroker.EventBroker(this, {
78
61
  prefix: 'flow',
79
62
  durable: true,
80
63
  autoDelete: false
81
64
  });
82
- flowApi.on = on;
83
- flowApi.once = once;
84
- flowApi.waitFor = waitFor;
85
- Object.defineProperty(flowApi, 'broker', {
86
- enumerable: true,
87
- get: () => broker
88
- });
65
+ this.broker = broker;
66
+ this.on = on;
67
+ this.once = once;
68
+ this.waitFor = waitFor;
69
+ this.emitFatal = emitFatal;
89
70
  logger.debug(`<${id}> init, <${sourceId}> -> <${targetId}>`);
90
- return flowApi;
91
-
92
- function take(content = {}) {
93
- flowApi.looped = undefined;
94
- const {
95
- sequenceId
96
- } = content;
97
- logger.debug(`<${sequenceId} (${id})> take, target <${targetId}>`);
98
- ++counters.take;
99
- publishEvent('take', content);
100
- return true;
101
- }
71
+ }
102
72
 
103
- function discard(content = {}) {
104
- const {
105
- sequenceId = (0, _shared.getUniqueId)(id)
106
- } = content;
107
- const discardSequence = content.discardSequence = (content.discardSequence || []).slice();
108
-
109
- if (discardSequence.indexOf(targetId) > -1) {
110
- ++counters.looped;
111
- logger.debug(`<${id}> discard loop detected <${sourceId}> -> <${targetId}>. Stop.`);
112
- return publishEvent('looped', content);
113
- }
114
-
115
- discardSequence.push(sourceId);
116
- logger.debug(`<${sequenceId} (${id})> discard, target <${targetId}>`);
117
- ++counters.discard;
118
- publishEvent('discard', content);
119
- }
73
+ const proto = SequenceFlow.prototype;
74
+ Object.defineProperty(proto, 'counters', {
75
+ enumerable: true,
120
76
 
121
- function publishEvent(action, content) {
122
- const eventContent = createMessage({
123
- action,
124
- ...content
125
- });
126
- broker.publish('event', `flow.${action}`, eventContent, {
127
- type: action
128
- });
129
- }
130
-
131
- function createMessage(override) {
132
- return { ...override,
133
- id,
134
- type,
135
- name,
136
- sourceId,
137
- targetId,
138
- isSequenceFlow: true,
139
- isDefault,
140
- parent: (0, _messageHelper.cloneParent)(parent)
77
+ get() {
78
+ return { ...this[kCounters]
141
79
  };
142
80
  }
143
81
 
144
- function getState() {
145
- return {
146
- id,
147
- type,
148
- name,
149
- sourceId,
150
- targetId,
151
- isDefault,
152
- counters: { ...counters
153
- },
154
- broker: broker.getState()
155
- };
156
- }
82
+ });
157
83
 
158
- function recover(state) {
159
- counters = { ...counters,
160
- ...state.counters
161
- };
162
- broker.recover(state.broker);
163
- }
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[kCounters].take;
164
91
 
165
- function getApi(message) {
166
- return (0, _Api.FlowApi)(broker, message || {
167
- content: createMessage()
168
- });
169
- }
92
+ this._publishEvent('take', content);
93
+
94
+ return true;
95
+ };
170
96
 
171
- function stop() {
172
- broker.stop();
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[kCounters].looped;
105
+ this.logger.debug(`<${this.id}> discard loop detected <${this.sourceId}> -> <${this.targetId}>. Stop.`);
106
+ return this._publishEvent('looped', content);
173
107
  }
174
108
 
175
- function shake(message) {
176
- const content = (0, _messageHelper.cloneContent)(message.content);
177
- content.sequence = content.sequence || [];
178
- content.sequence.push({
179
- id,
180
- type,
181
- isSequenceFlow: true,
182
- targetId
183
- });
184
- if (content.id === targetId) return broker.publish('event', 'flow.shake.loop', content, {
185
- persistent: false,
186
- type: 'shake'
187
- });
109
+ discardSequence.push(this.sourceId);
110
+ this.logger.debug(`<${sequenceId} (${this.id})> discard, target <${this.targetId}>`);
111
+ ++this[kCounters].discard;
188
112
 
189
- for (const s of message.content.sequence) {
190
- if (s.id === id) return broker.publish('event', 'flow.shake.loop', content, {
191
- persistent: false,
192
- type: 'shake'
193
- });
194
- }
113
+ this._publishEvent('discard', content);
114
+ };
195
115
 
196
- broker.publish('event', 'flow.shake', content, {
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[kCounters], 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
+ });
151
+
152
+ for (const s of message.content.sequence) {
153
+ if (s.id === this.id) return this.broker.publish('event', 'flow.shake.loop', content, {
197
154
  persistent: false,
198
155
  type: 'shake'
199
156
  });
200
157
  }
201
158
 
202
- function getCondition() {
203
- const conditionExpression = behaviour.conditionExpression;
204
- if (!conditionExpression) return null;
205
- const {
206
- language
207
- } = conditionExpression;
208
- const script = environment.getScript(language, flowApi);
159
+ this.broker.publish('event', 'flow.shake', content, {
160
+ persistent: false,
161
+ type: 'shake'
162
+ });
163
+ };
209
164
 
210
- if (script) {
211
- return ScriptCondition(script, language);
212
- }
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);
213
172
 
214
- if (!conditionExpression.body) {
215
- const msg = language ? `Condition expression script ${language} is unsupported or was not registered` : 'Condition expression without body is unsupported';
216
- return emitFatal(new Error(msg), createMessage());
217
- }
173
+ if (script) {
174
+ return new ScriptCondition(this, script, language);
175
+ }
218
176
 
219
- 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());
220
180
  }
221
181
 
222
- function ScriptCondition(script, language) {
223
- return {
224
- language,
182
+ return new ExpressionCondition(this, conditionExpression.body);
183
+ };
225
184
 
226
- execute(message, callback) {
227
- try {
228
- return script.execute((0, _ExecutionScope.default)(flowApi, message), callback);
229
- } catch (err) {
230
- if (!callback) throw err;
231
- logger.error(`<${id}>`, err);
232
- callback(err);
233
- }
234
- }
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
+ };
235
197
 
236
- };
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);
237
224
  }
238
-
239
- function ExpressionCondition(expression) {
240
- return {
241
- execute: (message, callback) => {
242
- try {
243
- const result = environment.resolveExpression(expression, createMessage(message));
244
- if (callback) return callback(null, result);
245
- return result;
246
- } catch (err) {
247
- if (callback) return callback(err);
248
- throw err;
249
- }
250
- }
251
- };
225
+ };
226
+
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;
252
243
  }
253
- }
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 kCompleted = Symbol.for('completed');
16
+ const kTargets = 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[kTargets] = 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[kTargets];
39
+ this[kCompleted] = 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[kCompleted] && 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[kTargets]) {
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[kCompleted] = 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[kTargets]) {
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[kCompleted] = 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[kTargets]) 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
+ };