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