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
|
@@ -5,507 +5,820 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = DefinitionExecution;
|
|
7
7
|
|
|
8
|
+
var _getPropertyValue = _interopRequireDefault(require("../getPropertyValue"));
|
|
9
|
+
|
|
8
10
|
var _Api = require("../Api");
|
|
9
11
|
|
|
10
|
-
var
|
|
12
|
+
var _shared = require("../shared");
|
|
11
13
|
|
|
12
|
-
var
|
|
14
|
+
var _messageHelper = require("../messageHelper");
|
|
13
15
|
|
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
const activatedSymbol = Symbol.for('activated');
|
|
19
|
+
const processesQSymbol = Symbol.for('processesQ');
|
|
20
|
+
const completedSymbol = Symbol.for('completed');
|
|
21
|
+
const executeMessageSymbol = Symbol.for('executeMessage');
|
|
22
|
+
const messageHandlersSymbol = Symbol.for('messageHandlers');
|
|
23
|
+
const parentSymbol = Symbol.for('definition');
|
|
24
|
+
const processesSymbol = Symbol.for('processes');
|
|
25
|
+
const statusSymbol = Symbol.for('status');
|
|
26
|
+
const stoppedSymbol = Symbol.for('stopped');
|
|
27
|
+
|
|
28
|
+
function DefinitionExecution(definition, context) {
|
|
29
|
+
const broker = definition.broker;
|
|
30
|
+
this[parentSymbol] = definition;
|
|
31
|
+
this.id = definition.id;
|
|
32
|
+
this.type = definition.type;
|
|
33
|
+
this.broker = broker;
|
|
34
|
+
this.environment = definition.environment;
|
|
35
|
+
this.context = context;
|
|
36
|
+
const processes = this[processesSymbol] = context.getProcesses();
|
|
37
|
+
this[processesSymbol] = {
|
|
38
|
+
processes,
|
|
39
|
+
running: [],
|
|
40
|
+
ids: processes.map(({
|
|
41
|
+
id: childId
|
|
42
|
+
}) => childId),
|
|
43
|
+
executable: context.getExecutableProcesses(),
|
|
44
|
+
postponed: []
|
|
45
|
+
};
|
|
30
46
|
broker.assertExchange('execution', 'topic', {
|
|
31
47
|
autoDelete: false,
|
|
32
48
|
durable: true
|
|
33
49
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
broker.assertQueue('activity-q', {
|
|
51
|
+
autoDelete: false,
|
|
52
|
+
durable: false
|
|
53
|
+
});
|
|
54
|
+
this[completedSymbol] = false;
|
|
55
|
+
this[stoppedSymbol] = false;
|
|
56
|
+
this[activatedSymbol] = false;
|
|
57
|
+
this[statusSymbol] = 'init';
|
|
58
|
+
this.executionId = undefined;
|
|
59
|
+
this[messageHandlersSymbol] = {
|
|
60
|
+
onApiMessage: this._onApiMessage.bind(this),
|
|
61
|
+
onCallActivity: this._onCallActivity.bind(this),
|
|
62
|
+
onCancelCallActivity: this._onCancelCallActivity.bind(this),
|
|
63
|
+
onChildEvent: this._onChildEvent.bind(this),
|
|
64
|
+
onDelegateMessage: this._onDelegateMessage.bind(this),
|
|
65
|
+
onMessageOutbound: this._onMessageOutbound.bind(this),
|
|
66
|
+
onProcessMessage: this._onProcessMessage.bind(this)
|
|
67
|
+
};
|
|
68
|
+
}
|
|
45
69
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
70
|
+
const proto = DefinitionExecution.prototype;
|
|
71
|
+
Object.defineProperty(proto, 'stopped', {
|
|
72
|
+
enumerable: true,
|
|
49
73
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
74
|
+
get() {
|
|
75
|
+
return this[stoppedSymbol];
|
|
76
|
+
}
|
|
53
77
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
78
|
+
});
|
|
79
|
+
Object.defineProperty(proto, 'completed', {
|
|
80
|
+
enumerable: true,
|
|
57
81
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
82
|
+
get() {
|
|
83
|
+
return this[completedSymbol];
|
|
84
|
+
}
|
|
61
85
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
86
|
+
});
|
|
87
|
+
Object.defineProperty(proto, 'status', {
|
|
88
|
+
enumerable: true,
|
|
65
89
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
90
|
+
get() {
|
|
91
|
+
return this[statusSymbol];
|
|
92
|
+
}
|
|
69
93
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
},
|
|
94
|
+
});
|
|
95
|
+
Object.defineProperty(proto, 'processes', {
|
|
96
|
+
enumerable: true,
|
|
74
97
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
getState,
|
|
79
|
-
getPostponed,
|
|
80
|
-
execute,
|
|
81
|
-
resume,
|
|
82
|
-
recover,
|
|
83
|
-
stop
|
|
84
|
-
};
|
|
85
|
-
return definitionExecution;
|
|
86
|
-
|
|
87
|
-
function execute(executeMessage) {
|
|
88
|
-
if (!executeMessage) throw new Error('Definition execution requires message');
|
|
89
|
-
const {
|
|
90
|
-
content,
|
|
91
|
-
fields
|
|
92
|
-
} = executeMessage;
|
|
93
|
-
if (!content || !content.executionId) throw new Error('Definition execution requires execution id');
|
|
94
|
-
const isRedelivered = fields.redelivered;
|
|
95
|
-
executionId = content.executionId;
|
|
96
|
-
initMessage = (0, _messageHelper.cloneMessage)(executeMessage, {
|
|
97
|
-
executionId,
|
|
98
|
-
state: 'start'
|
|
99
|
-
});
|
|
100
|
-
stopped = false;
|
|
101
|
-
activityQ = broker.assertQueue(`execute-${executionId}-q`, {
|
|
102
|
-
durable: true,
|
|
103
|
-
autoDelete: false
|
|
104
|
-
});
|
|
98
|
+
get() {
|
|
99
|
+
return this[processesSymbol].running;
|
|
100
|
+
}
|
|
105
101
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(proto, 'postponedCount', {
|
|
104
|
+
get() {
|
|
105
|
+
return this[processesSymbol].postponed.length;
|
|
106
|
+
}
|
|
109
107
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(proto, 'isRunning', {
|
|
110
|
+
get() {
|
|
111
|
+
return this[activatedSymbol];
|
|
112
|
+
}
|
|
114
113
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
proto.execute = function execute(executeMessage) {
|
|
117
|
+
if (!executeMessage) throw new Error('Definition execution requires message');
|
|
118
|
+
const content = executeMessage.content;
|
|
119
|
+
const executionId = this.executionId = content.executionId;
|
|
120
|
+
if (!executionId) throw new Error('Definition execution requires execution id');
|
|
121
|
+
this[executeMessageSymbol] = (0, _messageHelper.cloneMessage)(executeMessage, {
|
|
122
|
+
executionId,
|
|
123
|
+
state: 'start'
|
|
124
|
+
});
|
|
125
|
+
this[stoppedSymbol] = false;
|
|
126
|
+
this[processesQSymbol] = this.broker.assertQueue(`execute-${executionId}-q`, {
|
|
127
|
+
durable: true,
|
|
128
|
+
autoDelete: false
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
if (executeMessage.fields.redelivered) {
|
|
132
|
+
return this.resume();
|
|
119
133
|
}
|
|
120
134
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
postponed.splice(0);
|
|
126
|
-
activityQ.consume(onProcessMessage, {
|
|
127
|
-
prefetch: 1000,
|
|
128
|
-
consumerTag: `_definition-activity-${executionId}`
|
|
129
|
-
});
|
|
130
|
-
if (completed) return complete('completed');
|
|
135
|
+
const {
|
|
136
|
+
running,
|
|
137
|
+
executable
|
|
138
|
+
} = this[processesSymbol];
|
|
131
139
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return start();
|
|
140
|
+
if (content.processId) {
|
|
141
|
+
const startWithProcess = this.getProcessById(content.processId);
|
|
135
142
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
143
|
+
if (startWithProcess) {
|
|
144
|
+
executable.splice(0);
|
|
145
|
+
executable.push(startWithProcess);
|
|
141
146
|
}
|
|
142
|
-
|
|
143
|
-
processes.forEach(p => p.resume());
|
|
144
147
|
}
|
|
145
148
|
|
|
146
|
-
|
|
147
|
-
if (!processes.length) {
|
|
148
|
-
return publishCompletionMessage('completed');
|
|
149
|
-
}
|
|
149
|
+
this._debug('execute definition');
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
return complete('error', {
|
|
153
|
-
error: new Error('No executable process')
|
|
154
|
-
});
|
|
155
|
-
}
|
|
151
|
+
running.push(...executable);
|
|
156
152
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
153
|
+
this._activate(executable);
|
|
154
|
+
|
|
155
|
+
this._start();
|
|
156
|
+
|
|
157
|
+
return true;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
proto.resume = function resume() {
|
|
161
|
+
this._debug(`resume ${this.status} definition execution`);
|
|
162
|
+
|
|
163
|
+
if (this.completed) return this._complete('completed');
|
|
164
|
+
const {
|
|
165
|
+
running,
|
|
166
|
+
postponed
|
|
167
|
+
} = this[processesSymbol];
|
|
168
|
+
|
|
169
|
+
this._activate(running);
|
|
170
|
+
|
|
171
|
+
postponed.splice(0);
|
|
172
|
+
this[processesQSymbol].consume(this[messageHandlersSymbol].onProcessMessage, {
|
|
173
|
+
prefetch: 1000,
|
|
174
|
+
consumerTag: `_definition-activity-${this.executionId}`
|
|
175
|
+
});
|
|
176
|
+
if (this.completed) return this._complete('completed');
|
|
177
|
+
|
|
178
|
+
switch (this.status) {
|
|
179
|
+
case 'init':
|
|
180
|
+
return this._start();
|
|
181
|
+
|
|
182
|
+
case 'executing':
|
|
183
|
+
{
|
|
184
|
+
if (!this.postponedCount) return this._complete('completed');
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
165
187
|
}
|
|
166
188
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
189
|
+
for (const bp of running) bp.resume();
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
proto.recover = function recover(state) {
|
|
193
|
+
if (!state) return this;
|
|
194
|
+
this.executionId = state.executionId;
|
|
195
|
+
this[stoppedSymbol] = state.stopped;
|
|
196
|
+
this[completedSymbol] = state.completed;
|
|
197
|
+
this[statusSymbol] = state.status;
|
|
198
|
+
|
|
199
|
+
this._debug(`recover ${this.status} definition execution`);
|
|
200
|
+
|
|
201
|
+
const running = this[processesSymbol].running;
|
|
202
|
+
running.splice(0);
|
|
203
|
+
state.processes.map(processState => {
|
|
204
|
+
const instance = this.context.getNewProcessById(processState.id);
|
|
205
|
+
if (!instance) return;
|
|
206
|
+
instance.recover(processState);
|
|
207
|
+
running.push(instance);
|
|
208
|
+
});
|
|
209
|
+
return this;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
proto.stop = function stop() {
|
|
213
|
+
this.getApi().stop();
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
proto.getProcesses = function getProcesses() {
|
|
217
|
+
const {
|
|
218
|
+
running,
|
|
219
|
+
processes
|
|
220
|
+
} = this[processesSymbol];
|
|
221
|
+
const result = running.slice();
|
|
222
|
+
|
|
223
|
+
for (const bp of processes) {
|
|
224
|
+
if (!result.find(runningBp => bp.id === runningBp.id)) result.push(bp);
|
|
180
225
|
}
|
|
181
226
|
|
|
182
|
-
|
|
183
|
-
|
|
227
|
+
return result;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
proto.getProcessById = function getProcessById(processId) {
|
|
231
|
+
return this.getProcesses().find(bp => bp.id === processId);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
proto.getProcessesById = function getProcessesById(processId) {
|
|
235
|
+
return this.getProcesses().filter(bp => bp.id === processId);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
proto.getProcessByExecutionId = function getProcessByExecutionId(processExecutionId) {
|
|
239
|
+
const running = this[processesSymbol].running;
|
|
240
|
+
return running.find(bp => bp.executionId === processExecutionId);
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
proto.getRunningProcesses = function getRunningProcesses() {
|
|
244
|
+
const running = this[processesSymbol].running;
|
|
245
|
+
return running.filter(bp => bp.executionId);
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
proto.getExecutableProcesses = function getExecutableProcesses() {
|
|
249
|
+
return this[processesSymbol].executable.slice();
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
proto.getState = function getState() {
|
|
253
|
+
return {
|
|
254
|
+
executionId: this.executionId,
|
|
255
|
+
stopped: this.stopped,
|
|
256
|
+
completed: this.completed,
|
|
257
|
+
status: this.status,
|
|
258
|
+
processes: this[processesSymbol].running.map(bp => bp.getState())
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
proto.getApi = function getApi(apiMessage) {
|
|
263
|
+
if (!apiMessage) apiMessage = this[executeMessageSymbol] || {
|
|
264
|
+
content: this._createMessage()
|
|
265
|
+
};
|
|
266
|
+
const content = apiMessage.content;
|
|
267
|
+
|
|
268
|
+
if (content.executionId !== this.executionId) {
|
|
269
|
+
return this._getProcessApi(apiMessage);
|
|
184
270
|
}
|
|
185
271
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
consumerTag: '_definition-api-consumer'
|
|
190
|
-
});
|
|
191
|
-
processes.forEach(p => {
|
|
192
|
-
p.broker.subscribeTmp('message', 'message.outbound', onMessageOutbound, {
|
|
193
|
-
noAck: true,
|
|
194
|
-
consumerTag: '_definition-outbound-message-consumer'
|
|
195
|
-
});
|
|
196
|
-
p.broker.subscribeTmp('event', 'activity.signal', onDelegateMessage, {
|
|
197
|
-
noAck: true,
|
|
198
|
-
consumerTag: '_definition-signal-consumer',
|
|
199
|
-
priority: 200
|
|
200
|
-
});
|
|
201
|
-
p.broker.subscribeTmp('event', 'activity.message', onDelegateMessage, {
|
|
202
|
-
noAck: true,
|
|
203
|
-
consumerTag: '_definition-message-consumer',
|
|
204
|
-
priority: 200
|
|
205
|
-
});
|
|
206
|
-
p.broker.subscribeTmp('event', '#', onEvent, {
|
|
207
|
-
noAck: true,
|
|
208
|
-
consumerTag: '_definition-activity-consumer',
|
|
209
|
-
priority: 100
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
activated = true;
|
|
213
|
-
|
|
214
|
-
function onEvent(routingKey, originalMessage) {
|
|
215
|
-
const message = (0, _messageHelper.cloneMessage)(originalMessage);
|
|
216
|
-
const content = message.content;
|
|
217
|
-
const parent = content.parent = content.parent || {};
|
|
218
|
-
const isDirectChild = processIds.indexOf(content.id) > -1;
|
|
219
|
-
|
|
220
|
-
if (isDirectChild) {
|
|
221
|
-
parent.executionId = executionId;
|
|
222
|
-
} else {
|
|
223
|
-
content.parent = (0, _messageHelper.pushParent)(parent, {
|
|
224
|
-
id,
|
|
225
|
-
type,
|
|
226
|
-
executionId
|
|
227
|
-
});
|
|
228
|
-
}
|
|
272
|
+
const api = (0, _Api.DefinitionApi)(this.broker, apiMessage);
|
|
273
|
+
const postponed = this[processesSymbol].postponed;
|
|
274
|
+
const self = this;
|
|
229
275
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
276
|
+
api.getExecuting = function getExecuting() {
|
|
277
|
+
return postponed.reduce((result, msg) => {
|
|
278
|
+
const bpApi = self._getProcessApi(msg);
|
|
279
|
+
|
|
280
|
+
if (bpApi) result.push(bpApi);
|
|
281
|
+
return result;
|
|
282
|
+
}, []);
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
return api;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
proto.getPostponed = function getPostponed(...args) {
|
|
289
|
+
const running = this[processesSymbol].running;
|
|
290
|
+
return running.reduce((result, p) => {
|
|
291
|
+
result = result.concat(p.getPostponed(...args));
|
|
292
|
+
return result;
|
|
293
|
+
}, []);
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
proto._start = function start() {
|
|
297
|
+
const {
|
|
298
|
+
ids,
|
|
299
|
+
executable,
|
|
300
|
+
postponed
|
|
301
|
+
} = this[processesSymbol];
|
|
302
|
+
|
|
303
|
+
if (!ids.length) {
|
|
304
|
+
return this.publishCompletionMessage('completed');
|
|
236
305
|
}
|
|
237
306
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
processes.forEach(p => {
|
|
242
|
-
p.broker.cancel('_definition-outbound-message-consumer');
|
|
243
|
-
p.broker.cancel('_definition-activity-consumer');
|
|
244
|
-
p.broker.cancel('_definition-signal-consumer');
|
|
245
|
-
p.broker.cancel('_definition-message-consumer');
|
|
307
|
+
if (!executable.length) {
|
|
308
|
+
return this._complete('error', {
|
|
309
|
+
error: new Error('No executable process')
|
|
246
310
|
});
|
|
247
|
-
activated = false;
|
|
248
311
|
}
|
|
249
312
|
|
|
250
|
-
|
|
251
|
-
const content = message.content;
|
|
252
|
-
const isRedelivered = message.fields.redelivered;
|
|
253
|
-
const {
|
|
254
|
-
id: childId,
|
|
255
|
-
type: activityType,
|
|
256
|
-
executionId: childExecutionId
|
|
257
|
-
} = content;
|
|
258
|
-
if (isRedelivered && message.properties.persistent === false) return;
|
|
259
|
-
|
|
260
|
-
switch (routingKey) {
|
|
261
|
-
case 'execution.stop':
|
|
262
|
-
{
|
|
263
|
-
if (childExecutionId === executionId) {
|
|
264
|
-
message.ack();
|
|
265
|
-
return onStopped();
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
break;
|
|
269
|
-
}
|
|
313
|
+
this[statusSymbol] = 'start';
|
|
270
314
|
|
|
271
|
-
|
|
272
|
-
{
|
|
273
|
-
return onChildCompleted();
|
|
274
|
-
}
|
|
275
|
-
}
|
|
315
|
+
for (const bp of executable) bp.init();
|
|
276
316
|
|
|
277
|
-
|
|
317
|
+
for (const bp of executable) bp.run();
|
|
278
318
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
319
|
+
postponed.splice(0);
|
|
320
|
+
this[processesQSymbol].assertConsumer(this[messageHandlersSymbol].onProcessMessage, {
|
|
321
|
+
prefetch: 1000,
|
|
322
|
+
consumerTag: `_definition-activity-${this.executionId}`
|
|
323
|
+
});
|
|
324
|
+
};
|
|
284
325
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
complete('error', {
|
|
291
|
-
error: content.error
|
|
292
|
-
});
|
|
293
|
-
break;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
326
|
+
proto._activate = function activate(processList) {
|
|
327
|
+
this.broker.subscribeTmp('api', '#', this[messageHandlersSymbol].onApiMessage, {
|
|
328
|
+
noAck: true,
|
|
329
|
+
consumerTag: '_definition-api-consumer'
|
|
330
|
+
});
|
|
296
331
|
|
|
297
|
-
|
|
298
|
-
const previousMsg = popPostponed(childId);
|
|
299
|
-
if (previousMsg) previousMsg.ack();
|
|
300
|
-
if (postponeMessage) postponed.push(message);
|
|
301
|
-
}
|
|
332
|
+
for (const bp of processList) this._activateProcess(bp);
|
|
302
333
|
|
|
303
|
-
|
|
304
|
-
|
|
334
|
+
this[activatedSymbol] = true;
|
|
335
|
+
};
|
|
305
336
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
337
|
+
proto._activateProcess = function activateProcess(bp) {
|
|
338
|
+
const handlers = this[messageHandlersSymbol];
|
|
339
|
+
bp.broker.subscribeTmp('message', 'message.outbound', handlers.onMessageOutbound, {
|
|
340
|
+
noAck: true,
|
|
341
|
+
consumerTag: '_definition-outbound-message-consumer'
|
|
342
|
+
});
|
|
343
|
+
bp.broker.subscribeTmp('event', 'activity.signal', handlers.onDelegateMessage, {
|
|
344
|
+
noAck: true,
|
|
345
|
+
consumerTag: '_definition-signal-consumer',
|
|
346
|
+
priority: 200
|
|
347
|
+
});
|
|
348
|
+
bp.broker.subscribeTmp('event', 'activity.message', handlers.onDelegateMessage, {
|
|
349
|
+
noAck: true,
|
|
350
|
+
consumerTag: '_definition-message-consumer',
|
|
351
|
+
priority: 200
|
|
352
|
+
});
|
|
353
|
+
bp.broker.subscribeTmp('event', 'activity.call', handlers.onCallActivity, {
|
|
354
|
+
noAck: true,
|
|
355
|
+
consumerTag: '_definition-call-consumer',
|
|
356
|
+
priority: 200
|
|
357
|
+
});
|
|
358
|
+
bp.broker.subscribeTmp('event', 'activity.call.cancel', handlers.onCancelCallActivity, {
|
|
359
|
+
noAck: true,
|
|
360
|
+
consumerTag: '_definition-call-cancel-consumer',
|
|
361
|
+
priority: 200
|
|
362
|
+
});
|
|
363
|
+
bp.broker.subscribeTmp('event', '#', handlers.onChildEvent, {
|
|
364
|
+
noAck: true,
|
|
365
|
+
consumerTag: '_definition-activity-consumer',
|
|
366
|
+
priority: 100
|
|
367
|
+
});
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
proto._onChildEvent = function onChildEvent(routingKey, originalMessage) {
|
|
371
|
+
const message = (0, _messageHelper.cloneMessage)(originalMessage);
|
|
372
|
+
const content = message.content;
|
|
373
|
+
const parent = content.parent = content.parent || {};
|
|
374
|
+
const isDirectChild = this[processesSymbol].ids.indexOf(content.id) > -1;
|
|
375
|
+
|
|
376
|
+
if (isDirectChild) {
|
|
377
|
+
parent.executionId = this.executionId;
|
|
378
|
+
} else {
|
|
379
|
+
content.parent = (0, _messageHelper.pushParent)(parent, this);
|
|
380
|
+
}
|
|
310
381
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
382
|
+
this.broker.publish('event', routingKey, content, { ...message.properties,
|
|
383
|
+
mandatory: false
|
|
384
|
+
});
|
|
385
|
+
if (!isDirectChild) return;
|
|
386
|
+
this[processesQSymbol].queueMessage(message.fields, (0, _messageHelper.cloneContent)(content), message.properties);
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
proto._deactivate = function deactivate() {
|
|
390
|
+
this.broker.cancel('_definition-api-consumer');
|
|
391
|
+
this.broker.cancel(`_definition-activity-${this.executionId}`);
|
|
392
|
+
|
|
393
|
+
for (const bp of this[processesSymbol].running) this._deactivateProcess(bp);
|
|
394
|
+
|
|
395
|
+
this[activatedSymbol] = false;
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
proto._deactivateProcess = function deactivateProcess(bp) {
|
|
399
|
+
bp.broker.cancel('_definition-outbound-message-consumer');
|
|
400
|
+
bp.broker.cancel('_definition-activity-consumer');
|
|
401
|
+
bp.broker.cancel('_definition-signal-consumer');
|
|
402
|
+
bp.broker.cancel('_definition-message-consumer');
|
|
403
|
+
bp.broker.cancel('_definition-call-consumer');
|
|
404
|
+
bp.broker.cancel('_definition-call-cancel-consumer');
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
proto._onProcessMessage = function onProcessMessage(routingKey, message) {
|
|
408
|
+
const content = message.content;
|
|
409
|
+
const isRedelivered = message.fields.redelivered;
|
|
410
|
+
const {
|
|
411
|
+
id: childId,
|
|
412
|
+
executionId: childExecutionId,
|
|
413
|
+
inbound
|
|
414
|
+
} = content;
|
|
415
|
+
if (isRedelivered && message.properties.persistent === false) return;
|
|
416
|
+
|
|
417
|
+
switch (routingKey) {
|
|
418
|
+
case 'execution.stop':
|
|
419
|
+
{
|
|
420
|
+
if (childExecutionId === this.executionId) {
|
|
421
|
+
message.ack();
|
|
422
|
+
return this._onStopped(message);
|
|
423
|
+
}
|
|
315
424
|
|
|
316
|
-
|
|
317
|
-
message.ack();
|
|
318
|
-
complete('completed');
|
|
425
|
+
break;
|
|
319
426
|
}
|
|
320
|
-
}
|
|
321
427
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
processes.slice().forEach(p => {
|
|
327
|
-
p.stop();
|
|
328
|
-
});
|
|
329
|
-
stopped = true;
|
|
330
|
-
return broker.publish('execution', `execution.stopped.${executionId}`, { ...initMessage.content,
|
|
331
|
-
...content
|
|
332
|
-
}, {
|
|
333
|
-
type: 'stopped',
|
|
334
|
-
persistent: false
|
|
335
|
-
});
|
|
336
|
-
}
|
|
428
|
+
case 'process.leave':
|
|
429
|
+
{
|
|
430
|
+
return this._onProcessCompleted(message);
|
|
431
|
+
}
|
|
337
432
|
}
|
|
338
433
|
|
|
339
|
-
|
|
340
|
-
const messageType = message.properties.type;
|
|
341
|
-
const delegate = message.properties.delegate;
|
|
434
|
+
this._stateChangeMessage(message, true);
|
|
342
435
|
|
|
343
|
-
|
|
344
|
-
|
|
436
|
+
switch (routingKey) {
|
|
437
|
+
case 'process.discard':
|
|
438
|
+
case 'process.enter':
|
|
439
|
+
this[statusSymbol] = 'executing';
|
|
440
|
+
break;
|
|
345
441
|
|
|
346
|
-
|
|
347
|
-
|
|
442
|
+
case 'process.discarded':
|
|
443
|
+
{
|
|
444
|
+
if (inbound && inbound.length) {
|
|
445
|
+
const calledFrom = inbound[0];
|
|
348
446
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
bp.run();
|
|
447
|
+
this._getProcessApi({
|
|
448
|
+
content: calledFrom
|
|
449
|
+
}).cancel({
|
|
450
|
+
executionId: calledFrom.executionId
|
|
451
|
+
});
|
|
355
452
|
}
|
|
453
|
+
|
|
454
|
+
break;
|
|
356
455
|
}
|
|
357
|
-
}
|
|
358
456
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
457
|
+
case 'process.end':
|
|
458
|
+
{
|
|
459
|
+
if (inbound && inbound.length) {
|
|
460
|
+
const calledFrom = inbound[0];
|
|
461
|
+
|
|
462
|
+
this._getProcessApi({
|
|
463
|
+
content: calledFrom
|
|
464
|
+
}).signal({
|
|
465
|
+
executionId: calledFrom.executionId,
|
|
466
|
+
output: { ...content.output
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
} else {
|
|
470
|
+
Object.assign(this.environment.output, content.output);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
break;
|
|
362
474
|
}
|
|
363
|
-
}
|
|
364
475
|
|
|
365
|
-
|
|
476
|
+
case 'process.error':
|
|
477
|
+
{
|
|
478
|
+
if (inbound && inbound.length) {
|
|
479
|
+
const calledFrom = inbound[0];
|
|
480
|
+
|
|
481
|
+
this._getProcessApi({
|
|
482
|
+
content: calledFrom
|
|
483
|
+
}).sendApiMessage('error', {
|
|
484
|
+
executionId: calledFrom.executionId,
|
|
485
|
+
error: content.error
|
|
486
|
+
}, {
|
|
487
|
+
mandatory: true,
|
|
488
|
+
type: 'error'
|
|
489
|
+
});
|
|
490
|
+
} else {
|
|
491
|
+
for (const bp of this[processesSymbol].running.slice()) {
|
|
492
|
+
if (bp.id !== childId) bp.stop();
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
this._complete('error', {
|
|
496
|
+
error: content.error
|
|
497
|
+
});
|
|
498
|
+
}
|
|
366
499
|
|
|
367
|
-
switch (messageType) {
|
|
368
|
-
case 'stop':
|
|
369
|
-
activityQ.queueMessage({
|
|
370
|
-
routingKey: 'execution.stop'
|
|
371
|
-
}, (0, _messageHelper.cloneContent)(message.content), {
|
|
372
|
-
persistent: false
|
|
373
|
-
});
|
|
374
500
|
break;
|
|
375
|
-
|
|
501
|
+
}
|
|
376
502
|
}
|
|
503
|
+
};
|
|
377
504
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
completed,
|
|
383
|
-
status,
|
|
384
|
-
processes: processes.map(p => p.getState())
|
|
385
|
-
};
|
|
386
|
-
}
|
|
505
|
+
proto._stateChangeMessage = function stateChangeMessage(message, postponeMessage) {
|
|
506
|
+
let previousMsg;
|
|
507
|
+
const postponed = this[processesSymbol].postponed;
|
|
508
|
+
const idx = postponed.findIndex(msg => msg.content.executionId === message.content.executionId);
|
|
387
509
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
result = result.concat(p.getPostponed(...args));
|
|
391
|
-
return result;
|
|
392
|
-
}, []);
|
|
510
|
+
if (idx > -1) {
|
|
511
|
+
previousMsg = postponed.splice(idx, 1)[0];
|
|
393
512
|
}
|
|
394
513
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
514
|
+
if (previousMsg) previousMsg.ack();
|
|
515
|
+
if (postponeMessage) postponed.push(message);
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
proto._onProcessCompleted = function onProcessCompleted(message) {
|
|
519
|
+
this._stateChangeMessage(message, false);
|
|
520
|
+
|
|
521
|
+
if (message.fields.redelivered) return message.ack();
|
|
522
|
+
const {
|
|
523
|
+
id,
|
|
524
|
+
executionId,
|
|
525
|
+
type,
|
|
526
|
+
inbound
|
|
527
|
+
} = message.content;
|
|
528
|
+
|
|
529
|
+
this._debug(`left <${executionId} (${id})> (${type}), pending runs ${this.postponedCount}`);
|
|
530
|
+
|
|
531
|
+
if (inbound && inbound.length) {
|
|
532
|
+
const bp = this._removeProcessByExecutionId(executionId);
|
|
533
|
+
|
|
534
|
+
this._deactivateProcess(bp);
|
|
411
535
|
}
|
|
412
536
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
source
|
|
418
|
-
} = content;
|
|
419
|
-
logger.debug(`<${executionId} (${id})> conveying message from <${source.processId}.${source.id}> to`, target.id ? `<${target.processId}.${target.id}>` : `<${target.processId}>`);
|
|
420
|
-
const targetProcess = getProcessById(target.processId);
|
|
421
|
-
targetProcess.sendMessage(message);
|
|
537
|
+
if (!this.postponedCount) {
|
|
538
|
+
message.ack();
|
|
539
|
+
|
|
540
|
+
this._complete('completed');
|
|
422
541
|
}
|
|
542
|
+
};
|
|
423
543
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
544
|
+
proto._onStopped = function onStopped(message) {
|
|
545
|
+
const running = this[processesSymbol].running;
|
|
546
|
+
|
|
547
|
+
this._debug(`stop definition execution (stop process executions ${running.length})`);
|
|
548
|
+
|
|
549
|
+
this[processesQSymbol].close();
|
|
550
|
+
|
|
551
|
+
this._deactivate();
|
|
552
|
+
|
|
553
|
+
for (const bp of running.slice()) bp.stop();
|
|
554
|
+
|
|
555
|
+
this[stoppedSymbol] = true;
|
|
556
|
+
return this.broker.publish('execution', `execution.stopped.${this.executionId}`, (0, _messageHelper.cloneContent)(this[executeMessageSymbol].content, { ...message.content
|
|
557
|
+
}), {
|
|
558
|
+
type: 'stopped',
|
|
559
|
+
persistent: false
|
|
560
|
+
});
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
proto._onApiMessage = function onApiMessage(routingKey, message) {
|
|
564
|
+
const messageType = message.properties.type;
|
|
565
|
+
const delegate = message.properties.delegate;
|
|
566
|
+
|
|
567
|
+
if (delegate && this.id === message.content.id) {
|
|
568
|
+
const referenceId = (0, _getPropertyValue.default)(message, 'content.message.id');
|
|
569
|
+
|
|
570
|
+
this._startProcessesByMessage({
|
|
571
|
+
referenceId,
|
|
572
|
+
referenceType: messageType
|
|
442
573
|
});
|
|
443
574
|
}
|
|
444
575
|
|
|
445
|
-
|
|
446
|
-
|
|
576
|
+
if (delegate) {
|
|
577
|
+
for (const bp of this[processesSymbol].running.slice()) {
|
|
578
|
+
bp.broker.publish('api', routingKey, (0, _messageHelper.cloneContent)(message.content), message.properties);
|
|
579
|
+
}
|
|
447
580
|
}
|
|
448
581
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
582
|
+
if (this.executionId !== message.content.executionId) return;
|
|
583
|
+
|
|
584
|
+
if (messageType === 'stop') {
|
|
585
|
+
this[processesQSymbol].queueMessage({
|
|
586
|
+
routingKey: 'execution.stop'
|
|
587
|
+
}, (0, _messageHelper.cloneContent)(message.content), {
|
|
588
|
+
persistent: false
|
|
455
589
|
});
|
|
456
590
|
}
|
|
591
|
+
};
|
|
457
592
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
593
|
+
proto._startProcessesByMessage = function startProcessesByMessage(reference) {
|
|
594
|
+
const {
|
|
595
|
+
processes: bps,
|
|
596
|
+
running
|
|
597
|
+
} = this[processesSymbol];
|
|
598
|
+
if (bps.length < 2) return;
|
|
599
|
+
|
|
600
|
+
for (const bp of bps) {
|
|
601
|
+
if (bp.isExecutable) continue;
|
|
602
|
+
if (!bp.getStartActivities(reference).length) continue;
|
|
467
603
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
content: createMessage()
|
|
471
|
-
};
|
|
472
|
-
const content = apiMessage.content;
|
|
604
|
+
if (!bp.executionId) {
|
|
605
|
+
this._debug(`start <${bp.id}> by <${reference.referenceId}> (${reference.referenceType})`);
|
|
473
606
|
|
|
474
|
-
|
|
475
|
-
|
|
607
|
+
this._activateProcess(bp);
|
|
608
|
+
|
|
609
|
+
running.push(bp);
|
|
610
|
+
bp.init();
|
|
611
|
+
bp.run();
|
|
612
|
+
if (reference.referenceType === 'message') return;
|
|
613
|
+
continue;
|
|
476
614
|
}
|
|
477
615
|
|
|
478
|
-
|
|
616
|
+
this._debug(`start new <${bp.id}> by <${reference.referenceId}> (${reference.referenceType})`);
|
|
617
|
+
|
|
618
|
+
const targetProcess = this.context.getNewProcessById(bp.id);
|
|
479
619
|
|
|
480
|
-
|
|
481
|
-
return postponed.reduce((result, msg) => {
|
|
482
|
-
if (msg.content.executionId === content.executionId) return result;
|
|
483
|
-
result.push(getApi(msg));
|
|
484
|
-
return result;
|
|
485
|
-
}, []);
|
|
486
|
-
};
|
|
620
|
+
this._activateProcess(targetProcess);
|
|
487
621
|
|
|
488
|
-
|
|
622
|
+
running.push(targetProcess);
|
|
623
|
+
targetProcess.init();
|
|
624
|
+
targetProcess.run();
|
|
625
|
+
if (reference.referenceType === 'message') return;
|
|
489
626
|
}
|
|
627
|
+
};
|
|
490
628
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
629
|
+
proto._onMessageOutbound = function onMessageOutbound(routingKey, message) {
|
|
630
|
+
const content = message.content;
|
|
631
|
+
const {
|
|
632
|
+
target,
|
|
633
|
+
source
|
|
634
|
+
} = content;
|
|
635
|
+
|
|
636
|
+
this._debug(`conveying message from <${source.processId}.${source.id}> to`, target.id ? `<${target.processId}.${target.id}>` : `<${target.processId}>`);
|
|
499
637
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
638
|
+
const targetProcesses = this.getProcessesById(target.processId);
|
|
639
|
+
if (!targetProcesses.length) return;
|
|
640
|
+
let targetProcess, found;
|
|
641
|
+
|
|
642
|
+
for (const bp of targetProcesses) {
|
|
643
|
+
if (!bp.executionId) {
|
|
644
|
+
targetProcess = bp;
|
|
645
|
+
continue;
|
|
503
646
|
}
|
|
504
647
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
648
|
+
bp.sendMessage(message);
|
|
649
|
+
found = true;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
if (found) return;
|
|
653
|
+
targetProcess = targetProcess || this.context.getNewProcessById(target.processId);
|
|
654
|
+
|
|
655
|
+
this._activateProcess(targetProcess);
|
|
656
|
+
|
|
657
|
+
this[processesSymbol].running.push(targetProcess);
|
|
658
|
+
targetProcess.init();
|
|
659
|
+
targetProcess.run();
|
|
660
|
+
targetProcess.sendMessage(message);
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
proto._onCallActivity = function onCallActivity(routingKey, message) {
|
|
664
|
+
const content = message.content;
|
|
665
|
+
const {
|
|
666
|
+
calledElement,
|
|
667
|
+
id: fromId,
|
|
668
|
+
executionId: fromExecutionId,
|
|
669
|
+
name: fromName,
|
|
670
|
+
parent: fromParent
|
|
671
|
+
} = content;
|
|
672
|
+
if (!calledElement) return;
|
|
673
|
+
const bpExecutionId = `${(0, _shared.brokerSafeId)(calledElement)}_${fromExecutionId}`;
|
|
674
|
+
|
|
675
|
+
if (content.isRecovered) {
|
|
676
|
+
if (this.getProcessByExecutionId(bpExecutionId)) return;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
const targetProcess = this.context.getNewProcessById(calledElement, {
|
|
680
|
+
settings: {
|
|
681
|
+
calledFrom: (0, _messageHelper.cloneContent)({
|
|
682
|
+
id: fromId,
|
|
683
|
+
name: fromName,
|
|
684
|
+
executionId: content.executionId,
|
|
685
|
+
parent: content.parent
|
|
686
|
+
})
|
|
509
687
|
}
|
|
688
|
+
});
|
|
689
|
+
if (!targetProcess) return;
|
|
690
|
+
|
|
691
|
+
this._debug(`call from <${fromParent.id}.${fromId}> to <${calledElement}>`);
|
|
692
|
+
|
|
693
|
+
this._activateProcess(targetProcess);
|
|
694
|
+
|
|
695
|
+
this[processesSymbol].running.push(targetProcess);
|
|
696
|
+
targetProcess.init(bpExecutionId);
|
|
697
|
+
targetProcess.run({
|
|
698
|
+
inbound: [(0, _messageHelper.cloneContent)(content)]
|
|
699
|
+
});
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
proto._onCancelCallActivity = function onCancelCallActivity(routingKey, message) {
|
|
703
|
+
const {
|
|
704
|
+
calledElement,
|
|
705
|
+
id: fromId,
|
|
706
|
+
executionId: fromExecutionId,
|
|
707
|
+
parent: fromParent
|
|
708
|
+
} = message.content;
|
|
709
|
+
if (!calledElement) return;
|
|
710
|
+
const bpExecutionId = `${(0, _shared.brokerSafeId)(calledElement)}_${fromExecutionId}`;
|
|
711
|
+
const targetProcess = this.getProcessByExecutionId(bpExecutionId);
|
|
712
|
+
if (!targetProcess) return;
|
|
713
|
+
|
|
714
|
+
this._debug(`cancel call from <${fromParent.id}.${fromId}> to <${calledElement}>`);
|
|
715
|
+
|
|
716
|
+
targetProcess.getApi().discard();
|
|
717
|
+
};
|
|
718
|
+
|
|
719
|
+
proto._onDelegateMessage = function onDelegateMessage(routingKey, executeMessage) {
|
|
720
|
+
const content = executeMessage.content;
|
|
721
|
+
const messageType = executeMessage.properties.type;
|
|
722
|
+
const delegateMessage = executeMessage.content.message;
|
|
723
|
+
const reference = this.context.getActivityById(delegateMessage.id);
|
|
724
|
+
const message = reference && reference.resolve(executeMessage);
|
|
725
|
+
|
|
726
|
+
this._debug(`<${reference ? `${messageType} ${delegateMessage.id}>` : `anonymous ${messageType}`} event received from <${content.parent.id}.${content.id}>. Delegating.`);
|
|
727
|
+
|
|
728
|
+
this.getApi().sendApiMessage(messageType, {
|
|
729
|
+
source: {
|
|
730
|
+
id: content.id,
|
|
731
|
+
executionId: content.executionId,
|
|
732
|
+
type: content.type,
|
|
733
|
+
parent: (0, _messageHelper.cloneParent)(content.parent)
|
|
734
|
+
},
|
|
735
|
+
message,
|
|
736
|
+
originalMessage: content.message
|
|
737
|
+
}, {
|
|
738
|
+
delegate: true,
|
|
739
|
+
type: messageType
|
|
740
|
+
});
|
|
741
|
+
this.broker.publish('event', `definition.${messageType}`, this._createMessage({
|
|
742
|
+
message: message && (0, _messageHelper.cloneContent)(message)
|
|
743
|
+
}), {
|
|
744
|
+
type: messageType
|
|
745
|
+
});
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
proto._removeProcessByExecutionId = function removeProcessByExecutionId(processExecutionId) {
|
|
749
|
+
const running = this[processesSymbol].running;
|
|
750
|
+
const idx = running.findIndex(p => p.executionId === processExecutionId);
|
|
751
|
+
if (idx === -1) return;
|
|
752
|
+
return running.splice(idx, 1)[0];
|
|
753
|
+
};
|
|
754
|
+
|
|
755
|
+
proto._complete = function complete(completionType, content, options) {
|
|
756
|
+
this._deactivate();
|
|
757
|
+
|
|
758
|
+
const stateMessage = this[executeMessageSymbol];
|
|
759
|
+
|
|
760
|
+
this._debug(`definition execution ${completionType} in ${Date.now() - stateMessage.properties.timestamp}ms`);
|
|
761
|
+
|
|
762
|
+
if (!content) content = this._createMessage();
|
|
763
|
+
this[completedSymbol] = true;
|
|
764
|
+
if (this.status !== 'terminated') this[statusSymbol] = completionType;
|
|
765
|
+
this.broker.deleteQueue(this[processesQSymbol].name);
|
|
766
|
+
return this.broker.publish('execution', `execution.${completionType}.${this.executionId}`, { ...stateMessage.content,
|
|
767
|
+
output: { ...this.environment.output
|
|
768
|
+
},
|
|
769
|
+
...content,
|
|
770
|
+
state: completionType
|
|
771
|
+
}, {
|
|
772
|
+
type: completionType,
|
|
773
|
+
mandatory: completionType === 'error',
|
|
774
|
+
...options
|
|
775
|
+
});
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
proto.publishCompletionMessage = function publishCompletionMessage(completionType, content) {
|
|
779
|
+
this._deactivate();
|
|
780
|
+
|
|
781
|
+
this._debug(completionType);
|
|
782
|
+
|
|
783
|
+
if (!content) content = this._createMessage();
|
|
784
|
+
return this.broker.publish('execution', `execution.${completionType}.${this.executionId}`, content, {
|
|
785
|
+
type: completionType
|
|
786
|
+
});
|
|
787
|
+
};
|
|
788
|
+
|
|
789
|
+
proto._createMessage = function createMessage(content = {}) {
|
|
790
|
+
return {
|
|
791
|
+
id: this.id,
|
|
792
|
+
type: this.type,
|
|
793
|
+
executionId: this.executionId,
|
|
794
|
+
status: this.status,
|
|
795
|
+
...content
|
|
796
|
+
};
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
proto._getProcessApi = function getProcessApi(message) {
|
|
800
|
+
const content = message.content;
|
|
801
|
+
|
|
802
|
+
let api = this._getProcessApiByExecutionId(content.executionId, message);
|
|
803
|
+
|
|
804
|
+
if (api) return api;
|
|
805
|
+
if (!content.parent) return;
|
|
806
|
+
api = this._getProcessApiByExecutionId(content.parent.executionId, message);
|
|
807
|
+
if (api) return api;
|
|
808
|
+
if (!content.parent.path) return;
|
|
809
|
+
|
|
810
|
+
for (const pp of content.parent.path) {
|
|
811
|
+
api = this._getProcessApiByExecutionId(pp.executionId, message);
|
|
812
|
+
if (api) return api;
|
|
510
813
|
}
|
|
511
|
-
}
|
|
814
|
+
};
|
|
815
|
+
|
|
816
|
+
proto._getProcessApiByExecutionId = function getProcessApiByExecutionId(parentExecutionId, message) {
|
|
817
|
+
const processInstance = this.getProcessByExecutionId(parentExecutionId);
|
|
818
|
+
if (!processInstance) return;
|
|
819
|
+
return processInstance.getApi(message);
|
|
820
|
+
};
|
|
821
|
+
|
|
822
|
+
proto._debug = function debug(logMessage) {
|
|
823
|
+
this[parentSymbol].logger.debug(`<${this.executionId} (${this.id})> ${logMessage}`);
|
|
824
|
+
};
|