bpmn-elements 6.0.1 → 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 +3 -0
- package/dist/index.js +52 -44
- package/dist/src/Api.js +77 -76
- package/dist/src/Context.js +169 -175
- 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/activity/Activity.js +1106 -916
- 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 -100
- package/dist/src/flows/MessageFlow.js +86 -103
- package/dist/src/flows/SequenceFlow.js +173 -182
- 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 +17 -14
- package/dist/src/io/EnvironmentDataObject.js +33 -29
- package/dist/src/io/EnvironmentDataStore.js +33 -29
- package/dist/src/io/EnvironmentDataStoreReference.js +35 -31
- package/dist/src/io/InputOutputSpecification.js +177 -168
- package/dist/src/io/Properties.js +117 -124
- 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 +2 -2
- 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 +2 -0
- package/package.json +13 -13
- package/src/Api.js +65 -59
- package/src/Context.js +138 -141
- 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/activity/Activity.js +915 -775
- 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 -112
- package/src/flows/MessageFlow.js +81 -97
- package/src/flows/SequenceFlow.js +146 -160
- 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 +16 -15
- package/src/io/EnvironmentDataObject.js +29 -18
- package/src/io/EnvironmentDataStore.js +29 -18
- package/src/io/EnvironmentDataStoreReference.js +31 -20
- package/src/io/InputOutputSpecification.js +154 -157
- package/src/io/Properties.js +95 -97
- package/src/process/Process.js +374 -333
- package/src/process/ProcessExecution.js +606 -554
- 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,230 +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
|
-
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
|
-
} =
|
|
60
|
+
} = new _EventBroker.EventBroker(this, {
|
|
78
61
|
prefix: 'flow',
|
|
79
62
|
durable: true,
|
|
80
63
|
autoDelete: false
|
|
81
64
|
});
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
122
|
-
|
|
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[countersSymbol]
|
|
141
79
|
};
|
|
142
80
|
}
|
|
143
81
|
|
|
144
|
-
|
|
145
|
-
return {
|
|
146
|
-
id,
|
|
147
|
-
type,
|
|
148
|
-
name,
|
|
149
|
-
sourceId,
|
|
150
|
-
targetId,
|
|
151
|
-
isDefault,
|
|
152
|
-
counters: { ...counters
|
|
153
|
-
},
|
|
154
|
-
broker: broker.getState(true)
|
|
155
|
-
};
|
|
156
|
-
}
|
|
82
|
+
});
|
|
157
83
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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[countersSymbol].take;
|
|
164
91
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
92
|
+
this._publishEvent('take', content);
|
|
93
|
+
|
|
94
|
+
return true;
|
|
95
|
+
};
|
|
170
96
|
|
|
171
|
-
|
|
172
|
-
|
|
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);
|
|
173
107
|
}
|
|
174
108
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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[countersSymbol].discard;
|
|
188
112
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
persistent: false,
|
|
192
|
-
type: 'shake'
|
|
193
|
-
});
|
|
194
|
-
}
|
|
113
|
+
this._publishEvent('discard', content);
|
|
114
|
+
};
|
|
195
115
|
|
|
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
|
+
});
|
|
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
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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
|
-
|
|
211
|
-
|
|
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
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
173
|
+
if (script) {
|
|
174
|
+
return new ScriptCondition(this, script, language);
|
|
175
|
+
}
|
|
218
176
|
|
|
219
|
-
|
|
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
|
-
|
|
223
|
-
|
|
224
|
-
language,
|
|
182
|
+
return new ExpressionCondition(this, conditionExpression.body);
|
|
183
|
+
};
|
|
225
184
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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 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
|
+
};
|