bpmn-elements 17.2.2 → 18.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/README.md +3 -1
- package/dist/Api.js +83 -0
- package/dist/Context.js +228 -22
- package/dist/Environment.js +111 -31
- package/dist/EventBroker.js +57 -1
- package/dist/Expressions.js +3 -4
- package/dist/MessageFormatter.js +29 -16
- package/dist/Timers.js +13 -9
- package/dist/Tracker.js +1 -0
- package/dist/activity/Activity.js +458 -254
- package/dist/activity/ActivityExecution.js +113 -40
- package/dist/activity/Dummy.js +6 -1
- package/dist/activity/Escalation.js +36 -24
- package/dist/activity/ExecutionScope.js +1 -1
- package/dist/activity/Message.js +36 -24
- package/dist/activity/Signal.js +36 -24
- package/dist/activity/outbound-evaluator.js +1 -1
- package/dist/condition.js +12 -6
- package/dist/constants.js +21 -0
- package/dist/definition/Definition.js +182 -64
- package/dist/definition/DefinitionExecution.js +195 -82
- package/dist/error/BpmnError.js +12 -1
- package/dist/error/Errors.js +50 -9
- package/dist/eventDefinitions/CancelEventDefinition.js +29 -11
- package/dist/eventDefinitions/CompensateEventDefinition.js +51 -31
- package/dist/eventDefinitions/ConditionalEventDefinition.js +21 -9
- package/dist/eventDefinitions/ErrorEventDefinition.js +46 -30
- package/dist/eventDefinitions/EscalationEventDefinition.js +44 -27
- package/dist/eventDefinitions/EventDefinitionExecution.js +30 -23
- package/dist/eventDefinitions/LinkEventDefinition.js +45 -120
- package/dist/eventDefinitions/MessageEventDefinition.js +44 -29
- package/dist/eventDefinitions/SignalEventDefinition.js +46 -31
- package/dist/eventDefinitions/TerminateEventDefinition.js +10 -1
- package/dist/eventDefinitions/TimerEventDefinition.js +57 -37
- package/dist/eventDefinitions/index.js +20 -21
- package/dist/events/BoundaryEvent.js +52 -40
- package/dist/events/EndEvent.js +22 -8
- package/dist/events/IntermediateCatchEvent.js +26 -8
- package/dist/events/IntermediateThrowEvent.js +24 -9
- package/dist/events/StartEvent.js +30 -14
- package/dist/events/index.js +10 -11
- package/dist/flows/Association.js +50 -7
- package/dist/flows/MessageFlow.js +49 -10
- package/dist/flows/SequenceFlow.js +93 -22
- package/dist/flows/index.js +6 -7
- package/dist/gateways/EventBasedGateway.js +29 -15
- package/dist/gateways/ExclusiveGateway.js +20 -5
- package/dist/gateways/InclusiveGateway.js +21 -5
- package/dist/gateways/ParallelGateway.js +253 -15
- package/dist/gateways/index.js +8 -9
- package/dist/getPropertyValue.js +2 -2
- package/dist/index.js +42 -43
- package/dist/io/BpmnIO.js +15 -1
- package/dist/io/EnvironmentDataObject.js +29 -1
- package/dist/io/EnvironmentDataStore.js +24 -1
- package/dist/io/EnvironmentDataStoreReference.js +24 -1
- package/dist/io/InputOutputSpecification.js +21 -11
- package/dist/io/Properties.js +28 -17
- package/dist/messageHelper.js +41 -4
- package/dist/process/Lane.js +15 -4
- package/dist/process/Process.js +174 -76
- package/dist/process/ProcessExecution.js +362 -177
- package/dist/shared.js +2 -0
- package/dist/tasks/CallActivity.js +19 -4
- package/dist/tasks/LoopCharacteristics.js +94 -9
- package/dist/tasks/ReceiveTask.js +36 -21
- package/dist/tasks/ScriptTask.js +22 -6
- package/dist/tasks/ServiceImplementation.js +7 -4
- package/dist/tasks/ServiceTask.js +19 -4
- package/dist/tasks/SignalTask.js +19 -4
- package/dist/tasks/StandardLoopCharacteristics.js +8 -4
- package/dist/tasks/SubProcess.js +44 -29
- package/dist/tasks/Task.js +19 -4
- package/dist/tasks/Transaction.js +8 -4
- package/dist/tasks/index.js +16 -18
- package/package.json +31 -13
- package/src/Api.js +70 -0
- package/src/Context.js +200 -19
- package/src/Environment.js +99 -30
- package/src/EventBroker.js +46 -1
- package/src/Expressions.js +2 -3
- package/src/MessageFormatter.js +24 -16
- package/src/Timers.js +12 -9
- package/src/Tracker.js +1 -0
- package/src/activity/Activity.js +388 -231
- package/src/activity/ActivityExecution.js +93 -42
- package/src/activity/Dummy.js +6 -1
- package/src/activity/Escalation.js +25 -18
- package/src/activity/ExecutionScope.js +1 -1
- package/src/activity/Message.js +25 -18
- package/src/activity/Signal.js +25 -18
- package/src/activity/outbound-evaluator.js +1 -1
- package/src/condition.js +11 -5
- package/src/constants.js +15 -0
- package/src/definition/Definition.js +157 -62
- package/src/definition/DefinitionExecution.js +161 -83
- package/src/error/BpmnError.js +11 -1
- package/src/error/Errors.js +44 -5
- package/src/eventDefinitions/CancelEventDefinition.js +27 -13
- package/src/eventDefinitions/CompensateEventDefinition.js +48 -32
- package/src/eventDefinitions/ConditionalEventDefinition.js +20 -10
- package/src/eventDefinitions/ErrorEventDefinition.js +44 -33
- package/src/eventDefinitions/EscalationEventDefinition.js +39 -26
- package/src/eventDefinitions/EventDefinitionExecution.js +30 -24
- package/src/eventDefinitions/LinkEventDefinition.js +34 -120
- package/src/eventDefinitions/MessageEventDefinition.js +42 -31
- package/src/eventDefinitions/SignalEventDefinition.js +43 -32
- package/src/eventDefinitions/TerminateEventDefinition.js +9 -1
- package/src/eventDefinitions/TimerEventDefinition.js +53 -35
- package/src/eventDefinitions/index.js +10 -23
- package/src/events/BoundaryEvent.js +50 -39
- package/src/events/EndEvent.js +19 -7
- package/src/events/IntermediateCatchEvent.js +24 -8
- package/src/events/IntermediateThrowEvent.js +24 -8
- package/src/events/StartEvent.js +25 -14
- package/src/events/index.js +5 -18
- package/src/flows/Association.js +43 -9
- package/src/flows/MessageFlow.js +41 -10
- package/src/flows/SequenceFlow.js +82 -19
- package/src/flows/index.js +3 -4
- package/src/gateways/EventBasedGateway.js +27 -15
- package/src/gateways/ExclusiveGateway.js +16 -3
- package/src/gateways/InclusiveGateway.js +16 -3
- package/src/gateways/ParallelGateway.js +301 -10
- package/src/gateways/index.js +4 -4
- package/src/getPropertyValue.js +2 -2
- package/src/index.js +19 -19
- package/src/io/BpmnIO.js +13 -1
- package/src/io/EnvironmentDataObject.js +26 -1
- package/src/io/EnvironmentDataStore.js +22 -1
- package/src/io/EnvironmentDataStoreReference.js +22 -1
- package/src/io/InputOutputSpecification.js +17 -8
- package/src/io/Properties.js +23 -13
- package/src/messageHelper.js +36 -4
- package/src/process/Lane.js +14 -4
- package/src/process/Process.js +154 -72
- package/src/process/ProcessExecution.js +326 -175
- package/src/shared.js +1 -0
- package/src/tasks/CallActivity.js +16 -2
- package/src/tasks/LoopCharacteristics.js +77 -11
- package/src/tasks/ReceiveTask.js +33 -22
- package/src/tasks/ScriptTask.js +17 -3
- package/src/tasks/ServiceImplementation.js +6 -3
- package/src/tasks/ServiceTask.js +16 -2
- package/src/tasks/SignalTask.js +16 -2
- package/src/tasks/StandardLoopCharacteristics.js +7 -3
- package/src/tasks/SubProcess.js +37 -23
- package/src/tasks/Task.js +16 -2
- package/src/tasks/Transaction.js +7 -3
- package/src/tasks/index.js +8 -9
- package/types/bundle-errors.d.ts +1 -0
- package/types/bundle.d.ts +97 -0
- package/types/index.d.ts +2614 -84
- package/types/interfaces.d.ts +636 -0
- package/types/types.d.ts +0 -765
|
@@ -3,22 +3,24 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.ProcessExecution = ProcessExecution;
|
|
7
7
|
var _Api = require("../Api.js");
|
|
8
8
|
var _messageHelper = require("../messageHelper.js");
|
|
9
9
|
var _shared = require("../shared.js");
|
|
10
10
|
var _Tracker = require("../Tracker.js");
|
|
11
|
-
var
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
var _constants = require("../constants.js");
|
|
12
|
+
const K_ACTIVITY_Q = Symbol.for('activityQ');
|
|
13
|
+
const K_ELEMENTS = Symbol.for('elements');
|
|
14
|
+
const K_PARENT = Symbol.for('parent');
|
|
15
|
+
const K_TRACKER = Symbol.for('activity tracker');
|
|
16
|
+
const K_PEERS_DISCOVERED = Symbol.for('peers discovered');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Drives the execution of a single process or sub-process: activates children, routes activity
|
|
20
|
+
* events, and rolls completion up to the owning Process or sub-process Activity.
|
|
21
|
+
* @param {import('#types').Process | import('#types').Activity} parentActivity
|
|
22
|
+
* @param {import('#types').ContextInstance} context
|
|
23
|
+
*/
|
|
22
24
|
function ProcessExecution(parentActivity, context) {
|
|
23
25
|
const {
|
|
24
26
|
id,
|
|
@@ -27,7 +29,7 @@ function ProcessExecution(parentActivity, context) {
|
|
|
27
29
|
isSubProcess,
|
|
28
30
|
isTransaction
|
|
29
31
|
} = parentActivity;
|
|
30
|
-
this[
|
|
32
|
+
this[K_PARENT] = parentActivity;
|
|
31
33
|
this.id = id;
|
|
32
34
|
this.type = type;
|
|
33
35
|
this.isSubProcess = isSubProcess;
|
|
@@ -35,29 +37,30 @@ function ProcessExecution(parentActivity, context) {
|
|
|
35
37
|
this.broker = broker;
|
|
36
38
|
this.environment = context.environment;
|
|
37
39
|
this.context = context;
|
|
38
|
-
this[
|
|
40
|
+
this[K_ELEMENTS] = {
|
|
39
41
|
postponed: new Set(),
|
|
40
42
|
children: context.getActivities(id),
|
|
41
43
|
associations: context.getAssociations(id),
|
|
42
44
|
flows: context.getSequenceFlows(id),
|
|
43
45
|
outboundMessageFlows: context.getMessageFlows(id),
|
|
44
46
|
startActivities: new Set(),
|
|
47
|
+
startEventCount: 0,
|
|
45
48
|
triggeredByEvent: new Set(),
|
|
46
49
|
detachedActivities: new Set(),
|
|
47
|
-
|
|
50
|
+
convergingGateways: new Set()
|
|
48
51
|
};
|
|
49
52
|
const exchangeName = this._exchangeName = isSubProcess ? 'subprocess-execution' : 'execution';
|
|
50
53
|
broker.assertExchange(exchangeName, 'topic', {
|
|
51
54
|
autoDelete: false,
|
|
52
55
|
durable: true
|
|
53
56
|
});
|
|
54
|
-
this[
|
|
55
|
-
this[
|
|
56
|
-
this[
|
|
57
|
-
this[
|
|
58
|
-
this[
|
|
57
|
+
this[_constants.K_COMPLETED] = false;
|
|
58
|
+
this[_constants.K_STOPPED] = false;
|
|
59
|
+
this[_constants.K_ACTIVATED] = false;
|
|
60
|
+
this[_constants.K_STATUS] = 'init';
|
|
61
|
+
this[K_TRACKER] = new _Tracker.ActivityTracker(id);
|
|
59
62
|
this.executionId = undefined;
|
|
60
|
-
this[
|
|
63
|
+
this[_constants.K_MESSAGE_HANDLERS] = {
|
|
61
64
|
onActivityEvent: this._onActivityEvent.bind(this),
|
|
62
65
|
onApiMessage: this._onApiMessage.bind(this),
|
|
63
66
|
onChildMessage: this._onChildMessage.bind(this),
|
|
@@ -67,46 +70,52 @@ function ProcessExecution(parentActivity, context) {
|
|
|
67
70
|
Object.defineProperties(ProcessExecution.prototype, {
|
|
68
71
|
stopped: {
|
|
69
72
|
get() {
|
|
70
|
-
return this[
|
|
73
|
+
return this[_constants.K_STOPPED];
|
|
71
74
|
}
|
|
72
75
|
},
|
|
73
76
|
completed: {
|
|
74
77
|
get() {
|
|
75
|
-
return this[
|
|
78
|
+
return this[_constants.K_COMPLETED];
|
|
76
79
|
}
|
|
77
80
|
},
|
|
78
81
|
status: {
|
|
79
82
|
get() {
|
|
80
|
-
return this[
|
|
83
|
+
return this[_constants.K_STATUS];
|
|
81
84
|
}
|
|
82
85
|
},
|
|
83
86
|
postponedCount: {
|
|
84
87
|
get() {
|
|
85
|
-
return this[
|
|
88
|
+
return this[K_ELEMENTS].postponed.size;
|
|
86
89
|
}
|
|
87
90
|
},
|
|
88
91
|
isRunning: {
|
|
89
92
|
get() {
|
|
90
|
-
return this[
|
|
93
|
+
return this[_constants.K_ACTIVATED];
|
|
91
94
|
}
|
|
92
95
|
},
|
|
93
96
|
activityStatus: {
|
|
94
97
|
get() {
|
|
95
|
-
return this[
|
|
98
|
+
return this[K_TRACKER].activityStatus;
|
|
96
99
|
}
|
|
97
100
|
}
|
|
98
101
|
});
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Activate children and start the process execution. Resumes if the message is redelivered.
|
|
105
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
106
|
+
* @throws {Error} when message or executionId is missing
|
|
107
|
+
*/
|
|
99
108
|
ProcessExecution.prototype.execute = function execute(executeMessage) {
|
|
100
109
|
if (!executeMessage) throw new Error('Process execution requires message');
|
|
101
110
|
if (!executeMessage.content || !executeMessage.content.executionId) throw new Error('Process execution requires execution id');
|
|
102
111
|
const executionId = this.executionId = executeMessage.content.executionId;
|
|
103
|
-
this[
|
|
112
|
+
this[_constants.K_EXECUTE_MESSAGE] = (0, _messageHelper.cloneMessage)(executeMessage, {
|
|
104
113
|
executionId,
|
|
105
114
|
state: 'start'
|
|
106
115
|
});
|
|
107
|
-
this[
|
|
116
|
+
this[_constants.K_STOPPED] = false;
|
|
108
117
|
this.environment.assignVariables(executeMessage);
|
|
109
|
-
this[
|
|
118
|
+
this[K_ACTIVITY_Q] = this.broker.assertQueue(`execute-${executionId}-q`, {
|
|
110
119
|
durable: true,
|
|
111
120
|
autoDelete: false
|
|
112
121
|
});
|
|
@@ -118,28 +127,29 @@ ProcessExecution.prototype.execute = function execute(executeMessage) {
|
|
|
118
127
|
this._start();
|
|
119
128
|
return true;
|
|
120
129
|
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Resume after recover, resuming any postponed children.
|
|
133
|
+
*/
|
|
121
134
|
ProcessExecution.prototype.resume = function resume() {
|
|
122
135
|
this._debug(`resume process execution at ${this.status}`);
|
|
123
|
-
if (this[
|
|
136
|
+
if (this[_constants.K_COMPLETED]) return this._complete('completed');
|
|
124
137
|
this._activate();
|
|
125
138
|
const {
|
|
126
|
-
|
|
127
|
-
detachedActivities
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (startActivities.size > 1) {
|
|
131
|
-
for (const a of startActivities) a.shake();
|
|
132
|
-
}
|
|
139
|
+
postponed,
|
|
140
|
+
detachedActivities
|
|
141
|
+
} = this[K_ELEMENTS];
|
|
142
|
+
this._shakeOnStart();
|
|
133
143
|
postponed.clear();
|
|
134
144
|
detachedActivities.clear();
|
|
135
|
-
this[
|
|
145
|
+
this[K_ACTIVITY_Q].consume(this[_constants.K_MESSAGE_HANDLERS].onChildMessage, {
|
|
136
146
|
prefetch: 1000,
|
|
137
147
|
consumerTag: `_process-activity-${this.executionId}`
|
|
138
148
|
});
|
|
139
|
-
if (this[
|
|
149
|
+
if (this[_constants.K_COMPLETED]) return;
|
|
140
150
|
const status = this.status;
|
|
141
151
|
if (status === 'init') return this._start();
|
|
142
|
-
const tracker = this[
|
|
152
|
+
const tracker = this[K_TRACKER];
|
|
143
153
|
for (const msg of new Set(postponed)) {
|
|
144
154
|
const activity = this.getActivityById(msg.content.id);
|
|
145
155
|
if (!activity) continue;
|
|
@@ -152,16 +162,21 @@ ProcessExecution.prototype.resume = function resume() {
|
|
|
152
162
|
tracker.track(msg.fields.routingKey, msg);
|
|
153
163
|
activity.resume();
|
|
154
164
|
}
|
|
155
|
-
if (this[
|
|
165
|
+
if (this[_constants.K_COMPLETED]) return;
|
|
156
166
|
if (!postponed.size && status === 'executing') return this._complete('completed');
|
|
157
167
|
};
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Snapshot execution state including children, flows, message flows, and associations.
|
|
171
|
+
* @returns {import('#types').ProcessExecutionState}
|
|
172
|
+
*/
|
|
158
173
|
ProcessExecution.prototype.getState = function getState() {
|
|
159
174
|
const {
|
|
160
175
|
children,
|
|
161
176
|
flows,
|
|
162
177
|
outboundMessageFlows,
|
|
163
178
|
associations
|
|
164
|
-
} = this[
|
|
179
|
+
} = this[K_ELEMENTS];
|
|
165
180
|
const flowStates = flows.reduce((result, flow) => {
|
|
166
181
|
const elmState = flow.getState();
|
|
167
182
|
if (elmState) result.push(elmState);
|
|
@@ -169,8 +184,8 @@ ProcessExecution.prototype.getState = function getState() {
|
|
|
169
184
|
}, []);
|
|
170
185
|
return {
|
|
171
186
|
executionId: this.executionId,
|
|
172
|
-
stopped: this[
|
|
173
|
-
completed: this[
|
|
187
|
+
stopped: this[_constants.K_STOPPED],
|
|
188
|
+
completed: this[_constants.K_COMPLETED],
|
|
174
189
|
status: this.status,
|
|
175
190
|
children: children.reduce((result, activity) => {
|
|
176
191
|
if (activity.placeholder) return result;
|
|
@@ -189,12 +204,18 @@ ProcessExecution.prototype.getState = function getState() {
|
|
|
189
204
|
})
|
|
190
205
|
};
|
|
191
206
|
};
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Restore execution state captured by getState.
|
|
210
|
+
* @param {import('#types').ProcessExecutionState} [state]
|
|
211
|
+
* @returns {this}
|
|
212
|
+
*/
|
|
192
213
|
ProcessExecution.prototype.recover = function recover(state) {
|
|
193
214
|
if (!state) return this;
|
|
194
215
|
this.executionId = state.executionId;
|
|
195
|
-
this[
|
|
196
|
-
this[
|
|
197
|
-
this[
|
|
216
|
+
this[_constants.K_STOPPED] = state.stopped;
|
|
217
|
+
this[_constants.K_COMPLETED] = state.completed;
|
|
218
|
+
this[_constants.K_STATUS] = state.status;
|
|
198
219
|
this._debug(`recover process execution at ${this.status}`);
|
|
199
220
|
if (state.messageFlows) {
|
|
200
221
|
for (const flowState of state.messageFlows) {
|
|
@@ -226,53 +247,30 @@ ProcessExecution.prototype.recover = function recover(state) {
|
|
|
226
247
|
}
|
|
227
248
|
return this;
|
|
228
249
|
};
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Walk activity graph from the given start id, or every start activity when omitted.
|
|
253
|
+
* @param {string} [fromId]
|
|
254
|
+
* @returns {import('#types').ShakeResult}
|
|
255
|
+
*/
|
|
229
256
|
ProcessExecution.prototype.shake = function shake(fromId) {
|
|
230
|
-
|
|
231
|
-
const id = this.id;
|
|
232
|
-
if (!this.isRunning) {
|
|
233
|
-
executing = false;
|
|
234
|
-
this.executionId = (0, _shared.getUniqueId)(id);
|
|
235
|
-
this._activate();
|
|
236
|
-
}
|
|
237
|
-
const toShake = fromId ? [this.getActivityById(fromId)].filter(Boolean) : this[kElements].startActivities;
|
|
238
|
-
const result = {};
|
|
239
|
-
this.broker.subscribeTmp('event', '*.shake.*', (routingKey, {
|
|
240
|
-
content
|
|
241
|
-
}) => {
|
|
242
|
-
let isLooped = false;
|
|
243
|
-
switch (routingKey) {
|
|
244
|
-
case 'flow.shake.loop':
|
|
245
|
-
isLooped = true;
|
|
246
|
-
case 'activity.shake.end':
|
|
247
|
-
{
|
|
248
|
-
const {
|
|
249
|
-
id: shakeId,
|
|
250
|
-
parent: shakeParent
|
|
251
|
-
} = content;
|
|
252
|
-
if (shakeParent.id !== id) return;
|
|
253
|
-
result[shakeId] = result[shakeId] || [];
|
|
254
|
-
result[shakeId].push({
|
|
255
|
-
...content,
|
|
256
|
-
isLooped
|
|
257
|
-
});
|
|
258
|
-
break;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}, {
|
|
262
|
-
noAck: true,
|
|
263
|
-
consumerTag: `_shaker-${this.executionId}`
|
|
264
|
-
});
|
|
265
|
-
for (const a of toShake) a.shake();
|
|
266
|
-
if (!executing) this._deactivate();
|
|
267
|
-
this.broker.cancel(`_shaker-${this.executionId}`);
|
|
268
|
-
return result;
|
|
257
|
+
return Object.fromEntries(this._shakeElements(fromId).sequences);
|
|
269
258
|
};
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Stop the running process execution via the api.
|
|
262
|
+
*/
|
|
270
263
|
ProcessExecution.prototype.stop = function stop() {
|
|
271
264
|
this.getApi().stop();
|
|
272
265
|
};
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* List currently postponed children as Api wrappers.
|
|
269
|
+
* @param {import('#types').filterPostponed} [filterFn]
|
|
270
|
+
*/
|
|
273
271
|
ProcessExecution.prototype.getPostponed = function getPostponed(filterFn) {
|
|
274
272
|
const result = [];
|
|
275
|
-
for (const msg of this[
|
|
273
|
+
for (const msg of this[K_ELEMENTS].postponed) {
|
|
276
274
|
const api = this._getChildApi(msg);
|
|
277
275
|
if (!api) continue;
|
|
278
276
|
if (filterFn && !filterFn(api)) continue;
|
|
@@ -280,9 +278,13 @@ ProcessExecution.prototype.getPostponed = function getPostponed(filterFn) {
|
|
|
280
278
|
}
|
|
281
279
|
return result;
|
|
282
280
|
};
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Queue a discard message that propagates to all running children.
|
|
284
|
+
*/
|
|
283
285
|
ProcessExecution.prototype.discard = function discard() {
|
|
284
|
-
this[
|
|
285
|
-
|
|
286
|
+
this[_constants.K_STATUS] = 'discard';
|
|
287
|
+
this[K_ACTIVITY_Q].queueMessage({
|
|
286
288
|
routingKey: 'execution.discard'
|
|
287
289
|
}, {
|
|
288
290
|
id: this.id,
|
|
@@ -292,8 +294,12 @@ ProcessExecution.prototype.discard = function discard() {
|
|
|
292
294
|
type: 'discard'
|
|
293
295
|
});
|
|
294
296
|
};
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Queue a cancel message that propagates to all running children.
|
|
300
|
+
*/
|
|
295
301
|
ProcessExecution.prototype.cancel = function discard() {
|
|
296
|
-
|
|
302
|
+
this[K_ACTIVITY_Q].queueMessage({
|
|
297
303
|
routingKey: 'execution.cancel'
|
|
298
304
|
}, {
|
|
299
305
|
id: this.id,
|
|
@@ -303,26 +309,52 @@ ProcessExecution.prototype.cancel = function discard() {
|
|
|
303
309
|
type: 'cancel'
|
|
304
310
|
});
|
|
305
311
|
};
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Get child activities in the process scope.
|
|
315
|
+
* @returns {import('#types').Activity[]}
|
|
316
|
+
*/
|
|
306
317
|
ProcessExecution.prototype.getActivities = function getActivities() {
|
|
307
|
-
return this[
|
|
318
|
+
return this[K_ELEMENTS].children.slice();
|
|
308
319
|
};
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* @param {string} activityId
|
|
323
|
+
* @returns {import('#types').Activity}
|
|
324
|
+
*/
|
|
309
325
|
ProcessExecution.prototype.getActivityById = function getActivityById(activityId) {
|
|
310
|
-
return this[
|
|
326
|
+
return this[K_ELEMENTS].children.find(child => child.id === activityId);
|
|
311
327
|
};
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Get sequence flows in the process scope.
|
|
331
|
+
* @returns {import('#types').SequenceFlow}
|
|
332
|
+
*/
|
|
312
333
|
ProcessExecution.prototype.getSequenceFlows = function getSequenceFlows() {
|
|
313
|
-
return this[
|
|
334
|
+
return this[K_ELEMENTS].flows.slice();
|
|
314
335
|
};
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Get associations in the process scope.
|
|
339
|
+
* @returns {import('../flows/Association.js').Association}
|
|
340
|
+
*/
|
|
315
341
|
ProcessExecution.prototype.getAssociations = function getAssociations() {
|
|
316
|
-
return this[
|
|
342
|
+
return this[K_ELEMENTS].associations.slice();
|
|
317
343
|
};
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Resolve a process or child Api for the given message.
|
|
347
|
+
* @param {import('#types').ElementBrokerMessage} [message]
|
|
348
|
+
* @returns {import('#types').IApi<import('#types').Process>}
|
|
349
|
+
*/
|
|
318
350
|
ProcessExecution.prototype.getApi = function getApi(message) {
|
|
319
|
-
if (!message) return (0, _Api.ProcessApi)(this.broker, this[
|
|
351
|
+
if (!message) return (0, _Api.ProcessApi)(this.broker, this[_constants.K_EXECUTE_MESSAGE]);
|
|
320
352
|
const content = message.content;
|
|
321
353
|
if (content.executionId !== this.executionId) {
|
|
322
354
|
return this._getChildApi(message);
|
|
323
355
|
}
|
|
324
356
|
const api = (0, _Api.ProcessApi)(this.broker, message);
|
|
325
|
-
const postponed = this[
|
|
357
|
+
const postponed = this[K_ELEMENTS].postponed;
|
|
326
358
|
const self = this;
|
|
327
359
|
api.getExecuting = function getExecuting() {
|
|
328
360
|
const result = [];
|
|
@@ -334,13 +366,15 @@ ProcessExecution.prototype.getApi = function getApi(message) {
|
|
|
334
366
|
};
|
|
335
367
|
return api;
|
|
336
368
|
};
|
|
369
|
+
|
|
370
|
+
/** @internal */
|
|
337
371
|
ProcessExecution.prototype._start = function start() {
|
|
338
|
-
if (this[
|
|
372
|
+
if (!this[K_ELEMENTS].children.length) {
|
|
339
373
|
return this._complete('completed');
|
|
340
374
|
}
|
|
341
|
-
this[
|
|
375
|
+
this[_constants.K_STATUS] = 'start';
|
|
342
376
|
const executeContent = {
|
|
343
|
-
...this[
|
|
377
|
+
...this[_constants.K_EXECUTE_MESSAGE].content,
|
|
344
378
|
state: this.status
|
|
345
379
|
};
|
|
346
380
|
this.broker.publish(this._exchangeName, 'execute.start', (0, _messageHelper.cloneContent)(executeContent));
|
|
@@ -348,26 +382,31 @@ ProcessExecution.prototype._start = function start() {
|
|
|
348
382
|
startActivities,
|
|
349
383
|
postponed,
|
|
350
384
|
detachedActivities
|
|
351
|
-
} = this[
|
|
352
|
-
|
|
353
|
-
for (const a of startActivities) a.shake();
|
|
354
|
-
}
|
|
385
|
+
} = this[K_ELEMENTS];
|
|
386
|
+
this._shakeOnStart();
|
|
355
387
|
for (const a of startActivities) a.init();
|
|
356
|
-
this[
|
|
388
|
+
this[_constants.K_STATUS] = 'executing';
|
|
357
389
|
for (const a of startActivities) a.run();
|
|
390
|
+
if (!startActivities.size) {
|
|
391
|
+
for (const a of this[K_ELEMENTS].triggeredByEvent) {
|
|
392
|
+
if (a.isCatching && !a.isRunning) a.run();
|
|
393
|
+
}
|
|
394
|
+
}
|
|
358
395
|
postponed.clear();
|
|
359
396
|
detachedActivities.clear();
|
|
360
|
-
this[
|
|
397
|
+
this[K_ACTIVITY_Q].assertConsumer(this[_constants.K_MESSAGE_HANDLERS].onChildMessage, {
|
|
361
398
|
prefetch: 1000,
|
|
362
399
|
consumerTag: `_process-activity-${this.executionId}`
|
|
363
400
|
});
|
|
364
401
|
};
|
|
402
|
+
|
|
403
|
+
/** @internal */
|
|
365
404
|
ProcessExecution.prototype._activate = function activate() {
|
|
366
405
|
const {
|
|
367
406
|
onApiMessage,
|
|
368
407
|
onMessageFlowEvent,
|
|
369
408
|
onActivityEvent
|
|
370
|
-
} = this[
|
|
409
|
+
} = this[_constants.K_MESSAGE_HANDLERS];
|
|
371
410
|
if (!this.isSubProcess) {
|
|
372
411
|
this.broker.consume('api-q', onApiMessage, {
|
|
373
412
|
noAck: true,
|
|
@@ -387,8 +426,9 @@ ProcessExecution.prototype._activate = function activate() {
|
|
|
387
426
|
associations,
|
|
388
427
|
startActivities,
|
|
389
428
|
triggeredByEvent,
|
|
429
|
+
convergingGateways,
|
|
390
430
|
children
|
|
391
|
-
} = this[
|
|
431
|
+
} = this[K_ELEMENTS];
|
|
392
432
|
for (const flow of outboundMessageFlows) {
|
|
393
433
|
flow.activate();
|
|
394
434
|
flow.broker.subscribeTmp('event', '#', onMessageFlowEvent, {
|
|
@@ -413,6 +453,7 @@ ProcessExecution.prototype._activate = function activate() {
|
|
|
413
453
|
}
|
|
414
454
|
startActivities.clear();
|
|
415
455
|
triggeredByEvent.clear();
|
|
456
|
+
let startEventCount = 0;
|
|
416
457
|
for (const activity of children) {
|
|
417
458
|
if (activity.placeholder) continue;
|
|
418
459
|
activity.activate(this);
|
|
@@ -421,11 +462,18 @@ ProcessExecution.prototype._activate = function activate() {
|
|
|
421
462
|
consumerTag: '_process-activity-consumer',
|
|
422
463
|
priority: 200
|
|
423
464
|
});
|
|
424
|
-
if (activity.isStart)
|
|
425
|
-
|
|
465
|
+
if (activity.isStart) {
|
|
466
|
+
startActivities.add(activity);
|
|
467
|
+
if (activity.isStartEvent) startEventCount++;
|
|
468
|
+
}
|
|
469
|
+
if (activity.triggeredByEvent || activity.isCatching) triggeredByEvent.add(activity);
|
|
470
|
+
if (activity.isParallelGateway) convergingGateways.add(activity);
|
|
426
471
|
}
|
|
427
|
-
this[
|
|
472
|
+
this[K_ELEMENTS].startEventCount = startEventCount;
|
|
473
|
+
this[_constants.K_ACTIVATED] = true;
|
|
428
474
|
};
|
|
475
|
+
|
|
476
|
+
/** @internal */
|
|
429
477
|
ProcessExecution.prototype._deactivate = function deactivate() {
|
|
430
478
|
const broker = this.broker;
|
|
431
479
|
const executionId = this.executionId;
|
|
@@ -436,7 +484,7 @@ ProcessExecution.prototype._deactivate = function deactivate() {
|
|
|
436
484
|
flows,
|
|
437
485
|
associations,
|
|
438
486
|
outboundMessageFlows
|
|
439
|
-
} = this[
|
|
487
|
+
} = this[K_ELEMENTS];
|
|
440
488
|
for (const activity of children) {
|
|
441
489
|
if (activity.placeholder) continue;
|
|
442
490
|
activity.broker.cancel('_process-activity-consumer');
|
|
@@ -452,8 +500,105 @@ ProcessExecution.prototype._deactivate = function deactivate() {
|
|
|
452
500
|
flow.deactivate();
|
|
453
501
|
flow.broker.cancel('_process-message-consumer');
|
|
454
502
|
}
|
|
455
|
-
this[
|
|
503
|
+
this[_constants.K_ACTIVATED] = false;
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* Discover converging parallel gateway peers for the peer monitor, reusing already discovered ones.
|
|
508
|
+
* @internal
|
|
509
|
+
*/
|
|
510
|
+
ProcessExecution.prototype._shakeOnStart = function shakeOnStart() {
|
|
511
|
+
const convergingGateways = this[K_ELEMENTS].convergingGateways;
|
|
512
|
+
if (!convergingGateways.size) return;
|
|
513
|
+
if (this._peersDiscovered()) {
|
|
514
|
+
this._debug(`reuse discovered parallel gateway peers (${convergingGateways.size})`);
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
this._shakeElements();
|
|
518
|
+
this._debug(`forced shake to discover converging gateway peers (${convergingGateways.size})`);
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Whether every converging parallel gateway has discovered its peers in this runtime instance.
|
|
523
|
+
* Peers are a runtime cache and absent after recover, so a changed source is reshaken.
|
|
524
|
+
* @internal
|
|
525
|
+
*/
|
|
526
|
+
ProcessExecution.prototype._peersDiscovered = function peersDiscovered() {
|
|
527
|
+
const convergingGateways = this[K_ELEMENTS].convergingGateways;
|
|
528
|
+
for (const gateway of convergingGateways) {
|
|
529
|
+
if (!gateway[K_PEERS_DISCOVERED]) return false;
|
|
530
|
+
}
|
|
531
|
+
return true;
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
/** @internal */
|
|
535
|
+
ProcessExecution.prototype._shakeElements = function shakeElements(fromId) {
|
|
536
|
+
let executing = true;
|
|
537
|
+
const id = this.id;
|
|
538
|
+
if (!this.isRunning) {
|
|
539
|
+
executing = false;
|
|
540
|
+
this.executionId = (0, _shared.getUniqueId)(id);
|
|
541
|
+
this._activate();
|
|
542
|
+
}
|
|
543
|
+
const toShake = fromId ? [this.getActivityById(fromId)].filter(Boolean) : this[K_ELEMENTS].startActivities;
|
|
544
|
+
const result = {
|
|
545
|
+
sequences: new Map()
|
|
546
|
+
};
|
|
547
|
+
const convergingGateways = new Map();
|
|
548
|
+
const consumerTag = `_shaker-${this.executionId}`;
|
|
549
|
+
this.broker.subscribeTmp('event', '*.shake.*', (routingKey, {
|
|
550
|
+
content
|
|
551
|
+
}) => {
|
|
552
|
+
if (content.parent.id !== this.id) return;
|
|
553
|
+
switch (routingKey) {
|
|
554
|
+
case 'activity.shake.join':
|
|
555
|
+
{
|
|
556
|
+
const join = convergingGateways.get(content.join);
|
|
557
|
+
if (!join) {
|
|
558
|
+
convergingGateways.set(content.join, content);
|
|
559
|
+
} else {
|
|
560
|
+
join.sequence = join.sequence.concat(content.sequence);
|
|
561
|
+
}
|
|
562
|
+
break;
|
|
563
|
+
}
|
|
564
|
+
case 'flow.shake.loop':
|
|
565
|
+
case 'activity.shake.linked':
|
|
566
|
+
case 'activity.shake.end':
|
|
567
|
+
{
|
|
568
|
+
const {
|
|
569
|
+
id: shakeId,
|
|
570
|
+
parent: shakeParent
|
|
571
|
+
} = content;
|
|
572
|
+
if (shakeParent.id !== id) return;
|
|
573
|
+
let seqnce;
|
|
574
|
+
if (!(seqnce = result.sequences.get(shakeId))) {
|
|
575
|
+
seqnce = [];
|
|
576
|
+
result.sequences.set(shakeId, seqnce);
|
|
577
|
+
}
|
|
578
|
+
seqnce.push({
|
|
579
|
+
...content,
|
|
580
|
+
isLooped: routingKey === 'flow.shake.loop'
|
|
581
|
+
});
|
|
582
|
+
break;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}, {
|
|
586
|
+
noAck: true,
|
|
587
|
+
consumerTag
|
|
588
|
+
});
|
|
589
|
+
for (const a of toShake) a.shake();
|
|
590
|
+
for (const [aid, c] of convergingGateways.entries()) {
|
|
591
|
+
this._debug(`manual shake of converging gateway <${aid}>`);
|
|
592
|
+
this.getActivityById(aid).broker.publish('api', 'activity.shake.continue', c, {
|
|
593
|
+
type: 'shake'
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
if (!executing) this._deactivate();
|
|
597
|
+
this.broker.cancel(consumerTag);
|
|
598
|
+
return result;
|
|
456
599
|
};
|
|
600
|
+
|
|
601
|
+
/** @internal */
|
|
457
602
|
ProcessExecution.prototype._onDelegateEvent = function onDelegateEvent(message) {
|
|
458
603
|
const eventType = message.properties.type;
|
|
459
604
|
let delegate = true;
|
|
@@ -463,8 +608,8 @@ ProcessExecution.prototype._onDelegateEvent = function onDelegateEvent(message)
|
|
|
463
608
|
} else {
|
|
464
609
|
this._debug(`delegate ${eventType} anonymous event`);
|
|
465
610
|
}
|
|
466
|
-
for (const activity of this[
|
|
467
|
-
if (activity.getStartActivities({
|
|
611
|
+
for (const activity of this[K_ELEMENTS].triggeredByEvent) {
|
|
612
|
+
if (activity.isSubProcess && activity.getStartActivities({
|
|
468
613
|
referenceId: content.message?.id,
|
|
469
614
|
referenceType: eventType
|
|
470
615
|
}).length) {
|
|
@@ -477,15 +622,23 @@ ProcessExecution.prototype._onDelegateEvent = function onDelegateEvent(message)
|
|
|
477
622
|
});
|
|
478
623
|
return delegate;
|
|
479
624
|
};
|
|
625
|
+
|
|
626
|
+
/** @internal */
|
|
480
627
|
ProcessExecution.prototype._onMessageFlowEvent = function onMessageFlowEvent(routingKey, message) {
|
|
481
628
|
this.broker.publish('message', routingKey, (0, _messageHelper.cloneContent)(message.content), message.properties);
|
|
482
629
|
};
|
|
630
|
+
|
|
631
|
+
/** @internal */
|
|
483
632
|
ProcessExecution.prototype._onActivityEvent = function onActivityEvent(routingKey, message) {
|
|
484
|
-
|
|
485
|
-
|
|
633
|
+
const {
|
|
634
|
+
fields,
|
|
635
|
+
content,
|
|
636
|
+
properties
|
|
637
|
+
} = message;
|
|
638
|
+
if (fields.redelivered && properties.persistent === false) return;
|
|
486
639
|
const parent = content.parent = content.parent || {};
|
|
487
|
-
let delegate =
|
|
488
|
-
const shaking =
|
|
640
|
+
let delegate = properties.delegate;
|
|
641
|
+
const shaking = properties.type === 'shake';
|
|
489
642
|
const isDirectChild = content.parent.id === this.id;
|
|
490
643
|
if (isDirectChild) {
|
|
491
644
|
parent.executionId = this.executionId;
|
|
@@ -497,17 +650,17 @@ ProcessExecution.prototype._onActivityEvent = function onActivityEvent(routingKe
|
|
|
497
650
|
});
|
|
498
651
|
}
|
|
499
652
|
if (delegate) delegate = this._onDelegateEvent(message);
|
|
500
|
-
this[
|
|
653
|
+
this[K_TRACKER].track(routingKey, message);
|
|
501
654
|
this.broker.publish('event', routingKey, content, {
|
|
502
|
-
...
|
|
655
|
+
...properties,
|
|
503
656
|
delegate,
|
|
504
657
|
mandatory: false
|
|
505
658
|
});
|
|
506
|
-
if (shaking) return
|
|
659
|
+
if (shaking) return;
|
|
507
660
|
if (!isDirectChild) return;
|
|
508
661
|
switch (routingKey) {
|
|
509
662
|
case 'process.terminate':
|
|
510
|
-
return this[
|
|
663
|
+
return this[K_ACTIVITY_Q].queueMessage({
|
|
511
664
|
routingKey: 'execution.terminate'
|
|
512
665
|
}, (0, _messageHelper.cloneContent)(content), {
|
|
513
666
|
type: 'terminate',
|
|
@@ -516,11 +669,13 @@ ProcessExecution.prototype._onActivityEvent = function onActivityEvent(routingKe
|
|
|
516
669
|
case 'activity.stop':
|
|
517
670
|
return;
|
|
518
671
|
}
|
|
519
|
-
this[
|
|
672
|
+
this[K_ACTIVITY_Q].queueMessage(message.fields, (0, _messageHelper.cloneContent)(content), {
|
|
520
673
|
persistent: true,
|
|
521
674
|
...message.properties
|
|
522
675
|
});
|
|
523
676
|
};
|
|
677
|
+
|
|
678
|
+
/** @internal */
|
|
524
679
|
ProcessExecution.prototype._onChildMessage = function onChildMessage(routingKey, message) {
|
|
525
680
|
if (message.fields.redelivered && message.properties.persistent === false) return message.ack();
|
|
526
681
|
const content = message.content;
|
|
@@ -537,7 +692,7 @@ ProcessExecution.prototype._onChildMessage = function onChildMessage(routingKey,
|
|
|
537
692
|
case 'execution.discard.detached':
|
|
538
693
|
{
|
|
539
694
|
message.ack();
|
|
540
|
-
for (const detached of this[
|
|
695
|
+
for (const detached of this[K_ELEMENTS].detachedActivities) {
|
|
541
696
|
this._getChildApi(detached).discard();
|
|
542
697
|
}
|
|
543
698
|
return;
|
|
@@ -548,7 +703,7 @@ ProcessExecution.prototype._onChildMessage = function onChildMessage(routingKey,
|
|
|
548
703
|
case 'activity.error.caught':
|
|
549
704
|
{
|
|
550
705
|
let prevMsg;
|
|
551
|
-
for (const msg of this[
|
|
706
|
+
for (const msg of this[K_ELEMENTS].postponed) {
|
|
552
707
|
if (msg.content.executionId === content.executionId) {
|
|
553
708
|
prevMsg = msg;
|
|
554
709
|
break;
|
|
@@ -557,7 +712,6 @@ ProcessExecution.prototype._onChildMessage = function onChildMessage(routingKey,
|
|
|
557
712
|
if (!prevMsg) return message.ack();
|
|
558
713
|
break;
|
|
559
714
|
}
|
|
560
|
-
case 'flow.looped':
|
|
561
715
|
case 'activity.leave':
|
|
562
716
|
return this._onChildCompleted(message);
|
|
563
717
|
}
|
|
@@ -565,7 +719,7 @@ ProcessExecution.prototype._onChildMessage = function onChildMessage(routingKey,
|
|
|
565
719
|
switch (routingKey) {
|
|
566
720
|
case 'activity.detach':
|
|
567
721
|
{
|
|
568
|
-
this[
|
|
722
|
+
this[K_ELEMENTS].detachedActivities.add((0, _messageHelper.cloneMessage)(message));
|
|
569
723
|
break;
|
|
570
724
|
}
|
|
571
725
|
case 'activity.cancel':
|
|
@@ -584,17 +738,31 @@ ProcessExecution.prototype._onChildMessage = function onChildMessage(routingKey,
|
|
|
584
738
|
}
|
|
585
739
|
break;
|
|
586
740
|
}
|
|
741
|
+
case 'activity.end':
|
|
742
|
+
{
|
|
743
|
+
if (!content.isStartEvent) break;
|
|
744
|
+
const elements = this[K_ELEMENTS];
|
|
745
|
+
if (elements.startEventCount <= 1) break;
|
|
746
|
+
const startPeers = new Set();
|
|
747
|
+
for (const msg of elements.postponed) {
|
|
748
|
+
const peerId = msg.content.id;
|
|
749
|
+
if (peerId !== content.id && msg.content.isStartEvent) startPeers.add(msg);
|
|
750
|
+
}
|
|
751
|
+
elements.startEventCount = 0;
|
|
752
|
+
for (const msg of startPeers) this._getChildApi(msg).discard();
|
|
753
|
+
break;
|
|
754
|
+
}
|
|
587
755
|
case 'activity.error':
|
|
588
756
|
{
|
|
589
757
|
let eventCaughtBy;
|
|
590
|
-
for (const msg of this[
|
|
758
|
+
for (const msg of this[K_ELEMENTS].postponed) {
|
|
591
759
|
if (msg.fields.routingKey === 'activity.catch' && msg.content.source?.executionId === content.executionId) {
|
|
592
760
|
eventCaughtBy = msg;
|
|
593
761
|
break;
|
|
594
762
|
}
|
|
595
763
|
}
|
|
596
764
|
if (eventCaughtBy) {
|
|
597
|
-
this[
|
|
765
|
+
this[K_ACTIVITY_Q].queueMessage({
|
|
598
766
|
routingKey: 'activity.error.caught'
|
|
599
767
|
}, (0, _messageHelper.cloneContent)(content), {
|
|
600
768
|
persistent: true,
|
|
@@ -608,16 +776,20 @@ ProcessExecution.prototype._onChildMessage = function onChildMessage(routingKey,
|
|
|
608
776
|
}
|
|
609
777
|
}
|
|
610
778
|
};
|
|
779
|
+
|
|
780
|
+
/** @internal */
|
|
611
781
|
ProcessExecution.prototype._stateChangeMessage = function stateChangeMessage(message, postponeMessage) {
|
|
612
782
|
const previousMsg = this._popPostponed(message.content);
|
|
613
783
|
if (previousMsg) previousMsg.ack();
|
|
614
|
-
if (postponeMessage) this[
|
|
784
|
+
if (postponeMessage) this[K_ELEMENTS].postponed.add(message);
|
|
615
785
|
};
|
|
786
|
+
|
|
787
|
+
/** @internal */
|
|
616
788
|
ProcessExecution.prototype._popPostponed = function popPostponed(byContent) {
|
|
617
789
|
const {
|
|
618
790
|
postponed,
|
|
619
791
|
detachedActivities
|
|
620
|
-
} = this[
|
|
792
|
+
} = this[K_ELEMENTS];
|
|
621
793
|
let postponedMsg;
|
|
622
794
|
if (byContent.sequenceId) {
|
|
623
795
|
for (const msg of postponed) {
|
|
@@ -644,19 +816,25 @@ ProcessExecution.prototype._popPostponed = function popPostponed(byContent) {
|
|
|
644
816
|
}
|
|
645
817
|
return postponedMsg;
|
|
646
818
|
};
|
|
819
|
+
|
|
820
|
+
/** @internal */
|
|
647
821
|
ProcessExecution.prototype._onChildCompleted = function onChildCompleted(message) {
|
|
648
822
|
this._stateChangeMessage(message, false);
|
|
649
823
|
if (message.fields.redelivered) return message.ack();
|
|
650
824
|
const {
|
|
651
825
|
id,
|
|
652
826
|
type,
|
|
653
|
-
|
|
827
|
+
isParallelGateway
|
|
654
828
|
} = message.content;
|
|
829
|
+
if (isParallelGateway) {
|
|
830
|
+
for (const inb of message.content.inbound) {
|
|
831
|
+
this._popPostponed(inb)?.ack();
|
|
832
|
+
}
|
|
833
|
+
}
|
|
655
834
|
const {
|
|
656
835
|
postponed,
|
|
657
|
-
detachedActivities
|
|
658
|
-
|
|
659
|
-
} = this[kElements];
|
|
836
|
+
detachedActivities
|
|
837
|
+
} = this[K_ELEMENTS];
|
|
660
838
|
const postponedCount = postponed.size;
|
|
661
839
|
if (!postponedCount) {
|
|
662
840
|
this._debug(`left <${id}> (${type}), pending runs ${postponedCount}`);
|
|
@@ -664,9 +842,9 @@ ProcessExecution.prototype._onChildCompleted = function onChildCompleted(message
|
|
|
664
842
|
return this._complete('completed');
|
|
665
843
|
}
|
|
666
844
|
message.ack();
|
|
667
|
-
this._debug(`left <${id}> (${type}), pending activities ${postponedCount}`);
|
|
845
|
+
this._debug(`left <${id}> (${type}), pending activities ${postponedCount} ${[...postponed].map(m => m.content.id)}`);
|
|
668
846
|
if (postponedCount && postponedCount === detachedActivities.size) {
|
|
669
|
-
return this[
|
|
847
|
+
return this[K_ACTIVITY_Q].queueMessage({
|
|
670
848
|
routingKey: 'execution.discard.detached'
|
|
671
849
|
}, {
|
|
672
850
|
id: this.id,
|
|
@@ -676,21 +854,9 @@ ProcessExecution.prototype._onChildCompleted = function onChildCompleted(message
|
|
|
676
854
|
type: 'cancel'
|
|
677
855
|
});
|
|
678
856
|
}
|
|
679
|
-
if (isEnd && startActivities.size) {
|
|
680
|
-
const startSequences = this[kElements].startSequences;
|
|
681
|
-
for (const msg of postponed) {
|
|
682
|
-
const postponedId = msg.content.id;
|
|
683
|
-
const startSequence = startSequences[postponedId];
|
|
684
|
-
if (startSequence) {
|
|
685
|
-
if (startSequence.content.sequence.some(({
|
|
686
|
-
id: sid
|
|
687
|
-
}) => sid === id)) {
|
|
688
|
-
this._getChildApi(msg).discard();
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
857
|
};
|
|
858
|
+
|
|
859
|
+
/** @internal */
|
|
694
860
|
ProcessExecution.prototype._stopExecution = function stopExecution(message) {
|
|
695
861
|
const postponedCount = this.postponedCount;
|
|
696
862
|
this._debug(`stop process execution (stop child executions ${postponedCount})`);
|
|
@@ -698,18 +864,20 @@ ProcessExecution.prototype._stopExecution = function stopExecution(message) {
|
|
|
698
864
|
for (const api of this.getPostponed()) api.stop();
|
|
699
865
|
}
|
|
700
866
|
this._deactivate();
|
|
701
|
-
this[
|
|
867
|
+
this[_constants.K_STOPPED] = true;
|
|
702
868
|
return this.broker.publish(this._exchangeName, `execution.stopped.${this.executionId}`, {
|
|
703
|
-
...this[
|
|
869
|
+
...this[_constants.K_EXECUTE_MESSAGE].content,
|
|
704
870
|
...(message && message.content)
|
|
705
871
|
}, {
|
|
706
872
|
type: 'stopped',
|
|
707
873
|
persistent: false
|
|
708
874
|
});
|
|
709
875
|
};
|
|
876
|
+
|
|
877
|
+
/** @internal */
|
|
710
878
|
ProcessExecution.prototype._onDiscard = function onDiscard() {
|
|
711
879
|
this._deactivate();
|
|
712
|
-
const postponed = this[
|
|
880
|
+
const postponed = this[K_ELEMENTS].postponed;
|
|
713
881
|
const running = new Set(postponed);
|
|
714
882
|
postponed.clear();
|
|
715
883
|
this._debug(`discard process execution (discard child executions ${running.size})`);
|
|
@@ -720,17 +888,19 @@ ProcessExecution.prototype._onDiscard = function onDiscard() {
|
|
|
720
888
|
for (const flow of this.getAssociations()) flow.stop();
|
|
721
889
|
for (const msg of running) this._getChildApi(msg).discard();
|
|
722
890
|
}
|
|
723
|
-
this[
|
|
891
|
+
this[K_ACTIVITY_Q].purge();
|
|
724
892
|
return this._complete('discard');
|
|
725
893
|
};
|
|
894
|
+
|
|
895
|
+
/** @internal */
|
|
726
896
|
ProcessExecution.prototype._onCancel = function onCancel() {
|
|
727
|
-
const postponed = this[
|
|
897
|
+
const postponed = this[K_ELEMENTS].postponed;
|
|
728
898
|
const running = new Set(postponed);
|
|
729
899
|
const isTransaction = this.isTransaction;
|
|
730
900
|
if (isTransaction) {
|
|
731
901
|
this._debug(`cancel transaction execution (cancel child executions ${running.size})`);
|
|
732
|
-
this[
|
|
733
|
-
this.broker.publish('event', 'transaction.cancel', (0, _messageHelper.cloneMessage)(this[
|
|
902
|
+
this[_constants.K_STATUS] = 'cancel';
|
|
903
|
+
this.broker.publish('event', 'transaction.cancel', (0, _messageHelper.cloneMessage)(this[_constants.K_EXECUTE_MESSAGE], {
|
|
734
904
|
state: 'cancel'
|
|
735
905
|
}));
|
|
736
906
|
for (const msg of running) {
|
|
@@ -747,6 +917,8 @@ ProcessExecution.prototype._onCancel = function onCancel() {
|
|
|
747
917
|
}
|
|
748
918
|
}
|
|
749
919
|
};
|
|
920
|
+
|
|
921
|
+
/** @internal */
|
|
750
922
|
ProcessExecution.prototype._onApiMessage = function onApiMessage(routingKey, message) {
|
|
751
923
|
if (message.properties.delegate) {
|
|
752
924
|
return this._delegateApiMessage(routingKey, message);
|
|
@@ -763,7 +935,7 @@ ProcessExecution.prototype._onApiMessage = function onApiMessage(routingKey, mes
|
|
|
763
935
|
case 'discard':
|
|
764
936
|
return this.discard(message);
|
|
765
937
|
case 'stop':
|
|
766
|
-
this[
|
|
938
|
+
this[K_ACTIVITY_Q].queueMessage({
|
|
767
939
|
routingKey: 'execution.stop'
|
|
768
940
|
}, (0, _messageHelper.cloneContent)(message.content), {
|
|
769
941
|
persistent: false
|
|
@@ -771,6 +943,8 @@ ProcessExecution.prototype._onApiMessage = function onApiMessage(routingKey, mes
|
|
|
771
943
|
break;
|
|
772
944
|
}
|
|
773
945
|
};
|
|
946
|
+
|
|
947
|
+
/** @internal */
|
|
774
948
|
ProcessExecution.prototype._delegateApiMessage = function delegateApiMessage(routingKey, message, continueOnConsumed) {
|
|
775
949
|
const correlationId = message.properties.correlationId || (0, _shared.getUniqueId)(this.executionId);
|
|
776
950
|
this._debug(`delegate api ${routingKey} message to children, with correlationId <${correlationId}>`);
|
|
@@ -785,16 +959,18 @@ ProcessExecution.prototype._delegateApiMessage = function delegateApiMessage(rou
|
|
|
785
959
|
consumerTag: `_ct-delegate-${correlationId}`,
|
|
786
960
|
noAck: true
|
|
787
961
|
});
|
|
788
|
-
for (const child of this[
|
|
962
|
+
for (const child of this[K_ELEMENTS].children) {
|
|
789
963
|
if (child.placeholder) continue;
|
|
790
964
|
child.broker.publish('api', routingKey, (0, _messageHelper.cloneContent)(message.content), message.properties);
|
|
791
965
|
if (consumed && !continueOnConsumed) break;
|
|
792
966
|
}
|
|
793
967
|
return broker.cancel(`_ct-delegate-${correlationId}`);
|
|
794
968
|
};
|
|
969
|
+
|
|
970
|
+
/** @internal */
|
|
795
971
|
ProcessExecution.prototype._complete = function complete(completionType, content) {
|
|
796
972
|
this._deactivate();
|
|
797
|
-
this[
|
|
973
|
+
this[_constants.K_COMPLETED] = true;
|
|
798
974
|
const status = this.status;
|
|
799
975
|
switch (this.status) {
|
|
800
976
|
case 'cancel':
|
|
@@ -806,11 +982,11 @@ ProcessExecution.prototype._complete = function complete(completionType, content
|
|
|
806
982
|
break;
|
|
807
983
|
default:
|
|
808
984
|
this._debug(`process execution ${completionType}`);
|
|
809
|
-
this[
|
|
985
|
+
this[_constants.K_STATUS] = completionType;
|
|
810
986
|
}
|
|
811
987
|
const broker = this.broker;
|
|
812
|
-
this[
|
|
813
|
-
|
|
988
|
+
this[K_ACTIVITY_Q].delete();
|
|
989
|
+
broker.publish(this._exchangeName, `execution.${completionType}.${this.executionId}`, (0, _messageHelper.cloneContent)(this[_constants.K_EXECUTE_MESSAGE].content, {
|
|
814
990
|
output: {
|
|
815
991
|
...this.environment.output
|
|
816
992
|
},
|
|
@@ -821,10 +997,12 @@ ProcessExecution.prototype._complete = function complete(completionType, content
|
|
|
821
997
|
mandatory: completionType === 'error'
|
|
822
998
|
});
|
|
823
999
|
};
|
|
1000
|
+
|
|
1001
|
+
/** @internal */
|
|
824
1002
|
ProcessExecution.prototype._terminate = function terminate(message) {
|
|
825
|
-
this[
|
|
1003
|
+
this[_constants.K_STATUS] = 'terminated';
|
|
826
1004
|
this._debug('terminating process execution');
|
|
827
|
-
const postponed = this[
|
|
1005
|
+
const postponed = this[K_ELEMENTS].postponed;
|
|
828
1006
|
const running = new Set(postponed);
|
|
829
1007
|
postponed.clear();
|
|
830
1008
|
for (const flow of this.getSequenceFlows()) flow.stop();
|
|
@@ -840,20 +1018,30 @@ ProcessExecution.prototype._terminate = function terminate(message) {
|
|
|
840
1018
|
this._getChildApi(msg).stop();
|
|
841
1019
|
msg.ack();
|
|
842
1020
|
}
|
|
843
|
-
this[
|
|
1021
|
+
this[K_ACTIVITY_Q].purge();
|
|
844
1022
|
};
|
|
1023
|
+
|
|
1024
|
+
/** @internal */
|
|
845
1025
|
ProcessExecution.prototype._getFlowById = function getFlowById(flowId) {
|
|
846
|
-
return this[
|
|
1026
|
+
return this[K_ELEMENTS].flows.find(f => f.id === flowId);
|
|
847
1027
|
};
|
|
1028
|
+
|
|
1029
|
+
/** @internal */
|
|
848
1030
|
ProcessExecution.prototype._getAssociationById = function getAssociationById(associationId) {
|
|
849
|
-
return this[
|
|
1031
|
+
return this[K_ELEMENTS].associations.find(a => a.id === associationId);
|
|
850
1032
|
};
|
|
1033
|
+
|
|
1034
|
+
/** @internal */
|
|
851
1035
|
ProcessExecution.prototype._getMessageFlowById = function getMessageFlowById(flowId) {
|
|
852
|
-
return this[
|
|
1036
|
+
return this[K_ELEMENTS].outboundMessageFlows.find(f => f.id === flowId);
|
|
853
1037
|
};
|
|
1038
|
+
|
|
1039
|
+
/** @internal */
|
|
854
1040
|
ProcessExecution.prototype._getChildById = function getChildById(childId) {
|
|
855
1041
|
return this.getActivityById(childId) || this._getFlowById(childId);
|
|
856
1042
|
};
|
|
1043
|
+
|
|
1044
|
+
/** @internal */
|
|
857
1045
|
ProcessExecution.prototype._getChildApi = function getChildApi(message) {
|
|
858
1046
|
const content = message.content;
|
|
859
1047
|
let child = this._getChildById(content.id);
|
|
@@ -867,11 +1055,8 @@ ProcessExecution.prototype._getChildApi = function getChildApi(message) {
|
|
|
867
1055
|
if (child) return child.getApi(message);
|
|
868
1056
|
}
|
|
869
1057
|
};
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
if (routingKey !== 'activity.shake.end') return;
|
|
873
|
-
this[kElements].startSequences[message.content.id] = (0, _messageHelper.cloneMessage)(message);
|
|
874
|
-
};
|
|
1058
|
+
|
|
1059
|
+
/** @internal */
|
|
875
1060
|
ProcessExecution.prototype._debug = function debugMessage(logMessage) {
|
|
876
|
-
this[
|
|
1061
|
+
this[K_PARENT].logger.debug(`<${this.executionId} (${this.id})> ${logMessage}`);
|
|
877
1062
|
};
|