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.
- package/CHANGELOG.md +322 -0
- package/README.md +9 -3
- package/dist/index.js +71 -39
- package/dist/src/Api.js +77 -76
- package/dist/src/Context.js +169 -164
- package/dist/src/Environment.js +90 -102
- package/dist/src/EventBroker.js +89 -88
- package/dist/src/ExtensionsMapper.js +2 -2
- package/dist/src/MessageFormatter.js +164 -95
- package/dist/src/Scripts.js +6 -2
- package/dist/src/Timers.js +4 -6
- package/dist/src/activity/Activity.js +1108 -901
- package/dist/src/activity/ActivityExecution.js +342 -297
- package/dist/src/activity/Dummy.js +3 -3
- package/dist/src/definition/Definition.js +498 -444
- package/dist/src/definition/DefinitionExecution.js +722 -409
- package/dist/src/error/Errors.js +17 -7
- package/dist/src/eventDefinitions/CancelEventDefinition.js +190 -150
- package/dist/src/eventDefinitions/CompensateEventDefinition.js +194 -161
- package/dist/src/eventDefinitions/ConditionalEventDefinition.js +197 -135
- package/dist/src/eventDefinitions/ErrorEventDefinition.js +207 -165
- package/dist/src/eventDefinitions/EscalationEventDefinition.js +175 -141
- package/dist/src/eventDefinitions/EventDefinitionExecution.js +157 -129
- package/dist/src/eventDefinitions/LinkEventDefinition.js +174 -149
- package/dist/src/eventDefinitions/MessageEventDefinition.js +213 -176
- package/dist/src/eventDefinitions/SignalEventDefinition.js +203 -161
- package/dist/src/eventDefinitions/TerminateEventDefinition.js +21 -23
- package/dist/src/eventDefinitions/TimerEventDefinition.js +243 -228
- package/dist/src/events/BoundaryEvent.js +180 -144
- package/dist/src/events/EndEvent.js +18 -23
- package/dist/src/events/IntermediateCatchEvent.js +44 -58
- package/dist/src/events/IntermediateThrowEvent.js +18 -23
- package/dist/src/events/StartEvent.js +109 -94
- package/dist/src/flows/Association.js +94 -101
- package/dist/src/flows/MessageFlow.js +86 -103
- package/dist/src/flows/SequenceFlow.js +172 -184
- package/dist/src/gateways/EventBasedGateway.js +88 -84
- package/dist/src/gateways/ExclusiveGateway.js +13 -16
- package/dist/src/gateways/InclusiveGateway.js +11 -14
- package/dist/src/gateways/ParallelGateway.js +11 -14
- package/dist/src/getPropertyValue.js +34 -34
- package/dist/src/io/BpmnIO.js +31 -0
- package/dist/src/io/EnvironmentDataObject.js +33 -29
- package/dist/src/io/EnvironmentDataStore.js +52 -0
- package/dist/src/io/EnvironmentDataStoreReference.js +52 -0
- package/dist/src/io/InputOutputSpecification.js +177 -168
- package/dist/src/io/Properties.js +252 -0
- package/dist/src/messageHelper.js +1 -1
- package/dist/src/process/Process.js +433 -359
- package/dist/src/process/ProcessExecution.js +744 -645
- package/dist/src/shared.js +3 -6
- package/dist/src/tasks/CallActivity.js +160 -0
- package/dist/src/tasks/LoopCharacteristics.js +309 -330
- package/dist/src/tasks/ReceiveTask.js +233 -182
- package/dist/src/tasks/ScriptTask.js +35 -41
- package/dist/src/tasks/ServiceImplementation.js +13 -20
- package/dist/src/tasks/ServiceTask.js +82 -75
- package/dist/src/tasks/SignalTask.js +97 -93
- package/dist/src/tasks/StandardLoopCharacteristics.js +1 -1
- package/dist/src/tasks/SubProcess.js +195 -175
- package/dist/src/tasks/Task.js +17 -19
- package/index.js +8 -0
- package/package.json +16 -15
- package/src/Api.js +65 -59
- package/src/Context.js +142 -132
- package/src/Environment.js +88 -100
- package/src/EventBroker.js +67 -68
- package/src/ExtensionsMapper.js +2 -2
- package/src/MessageFormatter.js +132 -74
- package/src/Timers.js +4 -4
- package/src/activity/Activity.js +916 -757
- package/src/activity/ActivityExecution.js +293 -247
- package/src/activity/Dummy.js +2 -2
- package/src/definition/Definition.js +436 -401
- package/src/definition/DefinitionExecution.js +603 -343
- package/src/error/Errors.js +11 -6
- package/src/eventDefinitions/CancelEventDefinition.js +164 -121
- package/src/eventDefinitions/CompensateEventDefinition.js +158 -124
- package/src/eventDefinitions/ConditionalEventDefinition.js +147 -104
- package/src/eventDefinitions/ErrorEventDefinition.js +190 -131
- package/src/eventDefinitions/EscalationEventDefinition.js +139 -101
- package/src/eventDefinitions/EventDefinitionExecution.js +127 -95
- package/src/eventDefinitions/LinkEventDefinition.js +160 -129
- package/src/eventDefinitions/MessageEventDefinition.js +178 -121
- package/src/eventDefinitions/SignalEventDefinition.js +162 -106
- package/src/eventDefinitions/TerminateEventDefinition.js +19 -19
- package/src/eventDefinitions/TimerEventDefinition.js +202 -167
- package/src/events/BoundaryEvent.js +156 -115
- package/src/events/EndEvent.js +15 -18
- package/src/events/IntermediateCatchEvent.js +40 -44
- package/src/events/IntermediateThrowEvent.js +15 -18
- package/src/events/StartEvent.js +84 -50
- package/src/flows/Association.js +98 -113
- package/src/flows/MessageFlow.js +81 -97
- package/src/flows/SequenceFlow.js +145 -163
- package/src/gateways/EventBasedGateway.js +75 -68
- package/src/gateways/ExclusiveGateway.js +8 -13
- package/src/gateways/InclusiveGateway.js +8 -13
- package/src/gateways/ParallelGateway.js +8 -13
- package/src/getPropertyValue.js +34 -33
- package/src/io/BpmnIO.js +20 -0
- package/src/io/EnvironmentDataObject.js +29 -18
- package/src/io/EnvironmentDataStore.js +33 -0
- package/src/io/EnvironmentDataStoreReference.js +33 -0
- package/src/io/InputOutputSpecification.js +154 -157
- package/src/io/Properties.js +199 -0
- package/src/process/Process.js +374 -333
- package/src/process/ProcessExecution.js +606 -554
- package/src/shared.js +1 -5
- package/src/tasks/CallActivity.js +130 -0
- package/src/tasks/LoopCharacteristics.js +290 -289
- package/src/tasks/ReceiveTask.js +174 -107
- package/src/tasks/ScriptTask.js +27 -30
- package/src/tasks/ServiceImplementation.js +13 -18
- package/src/tasks/ServiceTask.js +67 -60
- package/src/tasks/SignalTask.js +77 -52
- package/src/tasks/StandardLoopCharacteristics.js +1 -1
- package/src/tasks/SubProcess.js +184 -157
- 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 =
|
|
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
|
|
31
|
+
parent,
|
|
28
32
|
targetId,
|
|
29
33
|
sourceId,
|
|
30
34
|
isDefault,
|
|
31
35
|
behaviour = {}
|
|
32
36
|
} = flowDef;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
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
|
-
} =
|
|
60
|
+
} = new _EventBroker.EventBroker(this, {
|
|
79
61
|
prefix: 'flow',
|
|
80
62
|
durable: true,
|
|
81
63
|
autoDelete: false
|
|
82
64
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
123
|
-
|
|
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
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
168
|
-
return (0, _Api.FlowApi)(broker, message || {
|
|
169
|
-
content: createMessage()
|
|
170
|
-
});
|
|
171
|
-
}
|
|
92
|
+
this._publishEvent('take', content);
|
|
172
93
|
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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
|
-
|
|
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
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
-
|
|
219
|
-
|
|
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
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
173
|
+
if (script) {
|
|
174
|
+
return new ScriptCondition(this, script, language);
|
|
175
|
+
}
|
|
226
176
|
|
|
227
|
-
|
|
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
|
-
|
|
231
|
-
|
|
232
|
-
language,
|
|
182
|
+
return new ExpressionCondition(this, conditionExpression.body);
|
|
183
|
+
};
|
|
233
184
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
return source;
|
|
25
|
+
this.id = id;
|
|
26
|
+
this.type = type;
|
|
27
|
+
this.broker = broker;
|
|
28
|
+
}
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
+
};
|