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
|
@@ -20,6 +20,15 @@ var _Errors = require("../error/Errors");
|
|
|
20
20
|
|
|
21
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
22
|
|
|
23
|
+
const consumingSymbol = Symbol.for('consuming');
|
|
24
|
+
const countersSymbol = Symbol.for('counters');
|
|
25
|
+
const execSymbol = Symbol.for('exec');
|
|
26
|
+
const executeMessageSymbol = Symbol.for('executeMessage');
|
|
27
|
+
const extensionsSymbol = Symbol.for('extensions');
|
|
28
|
+
const messageHandlersSymbol = Symbol.for('messageHandlers');
|
|
29
|
+
const stateMessageSymbol = Symbol.for('stateMessage');
|
|
30
|
+
const statusSymbol = Symbol.for('status');
|
|
31
|
+
const stoppedSymbol = Symbol.for('stopped');
|
|
23
32
|
var _default = Process;
|
|
24
33
|
exports.default = _default;
|
|
25
34
|
|
|
@@ -31,433 +40,498 @@ function Process(processDef, context) {
|
|
|
31
40
|
parent,
|
|
32
41
|
behaviour = {}
|
|
33
42
|
} = processDef;
|
|
34
|
-
|
|
43
|
+
this.id = id;
|
|
44
|
+
this.type = type;
|
|
45
|
+
this.name = name;
|
|
46
|
+
this.parent = parent ? (0, _messageHelper.cloneParent)(parent) : {};
|
|
47
|
+
this.behaviour = behaviour;
|
|
35
48
|
const {
|
|
36
49
|
isExecutable
|
|
37
50
|
} = behaviour;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
51
|
+
this.isExecutable = isExecutable;
|
|
52
|
+
const environment = this.environment = context.environment;
|
|
53
|
+
this.context = context;
|
|
54
|
+
this[countersSymbol] = {
|
|
41
55
|
completed: 0,
|
|
42
|
-
discarded: 0
|
|
43
|
-
terminated: 0
|
|
44
|
-
};
|
|
45
|
-
const processApi = {
|
|
46
|
-
id,
|
|
47
|
-
type,
|
|
48
|
-
name,
|
|
49
|
-
isExecutable,
|
|
50
|
-
behaviour,
|
|
51
|
-
|
|
52
|
-
get counters() {
|
|
53
|
-
return { ...counters
|
|
54
|
-
};
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
get executionId() {
|
|
58
|
-
return executionId;
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
get status() {
|
|
62
|
-
return status;
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
get stopped() {
|
|
66
|
-
return stopped;
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
get execution() {
|
|
70
|
-
return execution;
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
get isRunning() {
|
|
74
|
-
if (!consumingRunQ) return false;
|
|
75
|
-
return !!status;
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
context,
|
|
79
|
-
environment,
|
|
80
|
-
parent: { ...parent
|
|
81
|
-
},
|
|
82
|
-
logger,
|
|
83
|
-
getApi,
|
|
84
|
-
getActivities,
|
|
85
|
-
getActivityById,
|
|
86
|
-
getSequenceFlows,
|
|
87
|
-
getPostponed,
|
|
88
|
-
getStartActivities,
|
|
89
|
-
getState,
|
|
90
|
-
init,
|
|
91
|
-
recover,
|
|
92
|
-
resume,
|
|
93
|
-
run,
|
|
94
|
-
sendMessage,
|
|
95
|
-
shake,
|
|
96
|
-
signal,
|
|
97
|
-
cancelActivity,
|
|
98
|
-
stop
|
|
56
|
+
discarded: 0
|
|
99
57
|
};
|
|
58
|
+
this[stoppedSymbol] = false;
|
|
59
|
+
this[execSymbol] = {};
|
|
100
60
|
const {
|
|
101
61
|
broker,
|
|
102
62
|
on,
|
|
103
63
|
once,
|
|
104
64
|
waitFor
|
|
105
|
-
} = (0, _EventBroker.ProcessBroker)(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
get: () => extensions
|
|
119
|
-
});
|
|
120
|
-
return processApi;
|
|
121
|
-
|
|
122
|
-
function init() {
|
|
123
|
-
initExecutionId = (0, _shared.getUniqueId)(id);
|
|
124
|
-
logger.debug(`<${id}> initialized with executionId <${initExecutionId}>`);
|
|
125
|
-
publishEvent('init', createMessage({
|
|
126
|
-
executionId: initExecutionId
|
|
127
|
-
}));
|
|
128
|
-
}
|
|
65
|
+
} = (0, _EventBroker.ProcessBroker)(this);
|
|
66
|
+
this.broker = broker;
|
|
67
|
+
this.on = on;
|
|
68
|
+
this.once = once;
|
|
69
|
+
this.waitFor = waitFor;
|
|
70
|
+
this[messageHandlersSymbol] = {
|
|
71
|
+
onApiMessage: this._onApiMessage.bind(this),
|
|
72
|
+
onRunMessage: this._onRunMessage.bind(this),
|
|
73
|
+
onExecutionMessage: this._onExecutionMessage.bind(this)
|
|
74
|
+
};
|
|
75
|
+
this.logger = environment.Logger(type.toLowerCase());
|
|
76
|
+
this[extensionsSymbol] = context.loadExtensions(this);
|
|
77
|
+
}
|
|
129
78
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
initExecutionId = undefined;
|
|
134
|
-
const content = createMessage({ ...runContent,
|
|
135
|
-
executionId
|
|
136
|
-
});
|
|
137
|
-
broker.publish('run', 'run.enter', content);
|
|
138
|
-
broker.publish('run', 'run.start', (0, _messageHelper.cloneContent)(content));
|
|
139
|
-
broker.publish('run', 'run.execute', (0, _messageHelper.cloneContent)(content));
|
|
140
|
-
activateRunConsumers();
|
|
141
|
-
}
|
|
79
|
+
const proto = Process.prototype;
|
|
80
|
+
Object.defineProperty(proto, 'counters', {
|
|
81
|
+
enumerable: true,
|
|
142
82
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
if (!status) return processApi;
|
|
146
|
-
stopped = false;
|
|
147
|
-
const content = createMessage({
|
|
148
|
-
executionId
|
|
149
|
-
});
|
|
150
|
-
broker.publish('run', 'run.resume', content, {
|
|
151
|
-
persistent: false
|
|
152
|
-
});
|
|
153
|
-
activateRunConsumers();
|
|
154
|
-
return processApi;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function recover(state) {
|
|
158
|
-
if (processApi.isRunning) throw new Error(`cannot recover running process <${id}>`);
|
|
159
|
-
if (!state) return processApi;
|
|
160
|
-
stopped = state.stopped;
|
|
161
|
-
status = state.status;
|
|
162
|
-
executionId = state.executionId;
|
|
163
|
-
counters = { ...counters,
|
|
164
|
-
...state.counters
|
|
83
|
+
get() {
|
|
84
|
+
return { ...this[countersSymbol]
|
|
165
85
|
};
|
|
86
|
+
}
|
|
166
87
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(proto, 'extensions', {
|
|
90
|
+
enumerable: true,
|
|
170
91
|
|
|
171
|
-
|
|
172
|
-
return
|
|
92
|
+
get() {
|
|
93
|
+
return this[extensionsSymbol];
|
|
173
94
|
}
|
|
174
95
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
96
|
+
});
|
|
97
|
+
Object.defineProperty(proto, 'stopped', {
|
|
98
|
+
enumerable: true,
|
|
179
99
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
broker.subscribeTmp('api', `process.*.${executionId}`, onApiMessage, {
|
|
183
|
-
noAck: true,
|
|
184
|
-
consumerTag: '_process-api',
|
|
185
|
-
priority: 100
|
|
186
|
-
});
|
|
187
|
-
runQ.assertConsumer(onRunMessage, {
|
|
188
|
-
exclusive: true,
|
|
189
|
-
consumerTag: '_process-run'
|
|
190
|
-
});
|
|
100
|
+
get() {
|
|
101
|
+
return this[stoppedSymbol];
|
|
191
102
|
}
|
|
192
103
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
broker.cancel('_process-execution');
|
|
197
|
-
consumingRunQ = false;
|
|
198
|
-
}
|
|
104
|
+
});
|
|
105
|
+
Object.defineProperty(proto, 'isRunning', {
|
|
106
|
+
enumerable: true,
|
|
199
107
|
|
|
200
|
-
|
|
201
|
-
if (!
|
|
202
|
-
|
|
108
|
+
get() {
|
|
109
|
+
if (!this[consumingSymbol]) return false;
|
|
110
|
+
return !!this.status;
|
|
203
111
|
}
|
|
204
112
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
113
|
+
});
|
|
114
|
+
Object.defineProperty(proto, 'executionId', {
|
|
115
|
+
enumerable: true,
|
|
116
|
+
|
|
117
|
+
get() {
|
|
118
|
+
const {
|
|
119
|
+
executionId,
|
|
120
|
+
initExecutionId
|
|
121
|
+
} = this[execSymbol];
|
|
122
|
+
return executionId || initExecutionId;
|
|
208
123
|
}
|
|
209
124
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
125
|
+
});
|
|
126
|
+
Object.defineProperty(proto, 'execution', {
|
|
127
|
+
enumerable: true,
|
|
128
|
+
|
|
129
|
+
get() {
|
|
130
|
+
return this[execSymbol].execution;
|
|
214
131
|
}
|
|
215
132
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
133
|
+
});
|
|
134
|
+
Object.defineProperty(proto, 'status', {
|
|
135
|
+
enumerable: true,
|
|
136
|
+
|
|
137
|
+
get() {
|
|
138
|
+
return this[statusSymbol];
|
|
220
139
|
}
|
|
221
140
|
|
|
222
|
-
|
|
223
|
-
const {
|
|
224
|
-
content,
|
|
225
|
-
ack,
|
|
226
|
-
fields
|
|
227
|
-
} = message;
|
|
141
|
+
});
|
|
228
142
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
143
|
+
proto.init = function init(useAsExecutionId) {
|
|
144
|
+
const exec = this[execSymbol];
|
|
145
|
+
const initExecutionId = exec.initExecutionId = useAsExecutionId || (0, _shared.getUniqueId)(this.id);
|
|
232
146
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
switch (routingKey) {
|
|
236
|
-
case 'run.enter':
|
|
237
|
-
{
|
|
238
|
-
logger.debug(`<${id}> enter`);
|
|
239
|
-
status = 'entered';
|
|
240
|
-
if (fields.redelivered) break;
|
|
241
|
-
execution = undefined;
|
|
242
|
-
publishEvent('enter', content);
|
|
243
|
-
break;
|
|
244
|
-
}
|
|
147
|
+
this._debug(`initialized with executionId <${initExecutionId}>`);
|
|
245
148
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
publishEvent('start', content);
|
|
251
|
-
break;
|
|
252
|
-
}
|
|
149
|
+
this._publishEvent('init', this._createMessage({
|
|
150
|
+
executionId: initExecutionId
|
|
151
|
+
}));
|
|
152
|
+
};
|
|
253
153
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
if (fields.redelivered && !execution) {
|
|
260
|
-
executeMessage.fields.redelivered = undefined;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
postponedMessage = message;
|
|
264
|
-
executionQ.assertConsumer(onExecutionMessage, {
|
|
265
|
-
exclusive: true,
|
|
266
|
-
consumerTag: '_process-execution'
|
|
267
|
-
});
|
|
268
|
-
execution = execution || (0, _ProcessExecution.default)(processApi, context);
|
|
269
|
-
return execution.execute(executeMessage);
|
|
270
|
-
}
|
|
154
|
+
proto.run = function run(runContent) {
|
|
155
|
+
if (this.isRunning) throw new Error(`process <${this.id}> is already running`);
|
|
156
|
+
const exec = this[execSymbol];
|
|
157
|
+
const executionId = exec.executionId = exec.initExecutionId || (0, _shared.getUniqueId)(this.id);
|
|
158
|
+
exec.initExecutionId = undefined;
|
|
271
159
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
error: fields.redelivered ? (0, _Errors.makeErrorFromMessage)(message) : content.error
|
|
276
|
-
}));
|
|
277
|
-
break;
|
|
278
|
-
}
|
|
160
|
+
const content = this._createMessage({ ...runContent,
|
|
161
|
+
executionId
|
|
162
|
+
});
|
|
279
163
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
logger.debug(`<${id}> completed`);
|
|
285
|
-
counters.completed++;
|
|
286
|
-
broker.publish('run', 'run.leave', content);
|
|
287
|
-
publishEvent('end', content);
|
|
288
|
-
break;
|
|
289
|
-
}
|
|
164
|
+
const broker = this.broker;
|
|
165
|
+
broker.publish('run', 'run.enter', content);
|
|
166
|
+
broker.publish('run', 'run.start', (0, _messageHelper.cloneContent)(content));
|
|
167
|
+
broker.publish('run', 'run.execute', (0, _messageHelper.cloneContent)(content));
|
|
290
168
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
status = 'discarded';
|
|
294
|
-
if (fields.redelivered) break;
|
|
295
|
-
counters.discarded++;
|
|
296
|
-
broker.publish('run', 'run.leave', content);
|
|
297
|
-
break;
|
|
298
|
-
}
|
|
169
|
+
this._activateRunConsumers();
|
|
170
|
+
};
|
|
299
171
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
}
|
|
307
|
-
}
|
|
172
|
+
proto.resume = function resume() {
|
|
173
|
+
if (this.isRunning) throw new Error(`cannot resume running process <${this.id}>`);
|
|
174
|
+
if (!this.status) return this;
|
|
175
|
+
this[stoppedSymbol] = false;
|
|
176
|
+
|
|
177
|
+
const content = this._createMessage();
|
|
308
178
|
|
|
309
|
-
|
|
179
|
+
this.broker.publish('run', 'run.resume', content, {
|
|
180
|
+
persistent: false
|
|
181
|
+
});
|
|
310
182
|
|
|
311
|
-
|
|
312
|
-
message.ack();
|
|
183
|
+
this._activateRunConsumers();
|
|
313
184
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
case 'run.start':
|
|
317
|
-
case 'run.discarded':
|
|
318
|
-
case 'run.end':
|
|
319
|
-
case 'run.leave':
|
|
320
|
-
break;
|
|
185
|
+
return this;
|
|
186
|
+
};
|
|
321
187
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
188
|
+
proto.recover = function recover(state) {
|
|
189
|
+
if (this.isRunning) throw new Error(`cannot recover running process <${this.id}>`);
|
|
190
|
+
if (!state) return this;
|
|
191
|
+
this[stoppedSymbol] = !!state.stopped;
|
|
192
|
+
this[statusSymbol] = state.status;
|
|
193
|
+
const exec = this[execSymbol];
|
|
194
|
+
exec.executionId = state.executionId;
|
|
195
|
+
this[countersSymbol] = { ...this[countersSymbol],
|
|
196
|
+
...state.counters
|
|
197
|
+
};
|
|
198
|
+
this.environment.recover(state.environment);
|
|
199
|
+
|
|
200
|
+
if (state.execution) {
|
|
201
|
+
exec.execution = new _ProcessExecution.default(this, this.context).recover(state.execution);
|
|
202
|
+
}
|
|
325
203
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
204
|
+
this.broker.recover(state.broker);
|
|
205
|
+
return this;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
proto.shake = function shake(startId) {
|
|
209
|
+
if (this.isRunning) return this.execution.shake(startId);
|
|
210
|
+
return new _ProcessExecution.default(this, this.context).shake(startId);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
proto.stop = function stop() {
|
|
214
|
+
if (!this.isRunning) return;
|
|
215
|
+
this.getApi().stop();
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
proto.getApi = function getApi(message) {
|
|
219
|
+
const execution = this.execution;
|
|
220
|
+
if (execution) return execution.getApi(message);
|
|
221
|
+
return (0, _Api.ProcessApi)(this.broker, message || this[stateMessageSymbol]);
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
proto.signal = function signal(message) {
|
|
225
|
+
return this.getApi().signal(message, {
|
|
226
|
+
delegate: true
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
proto.getState = function getState() {
|
|
231
|
+
return this._createMessage({
|
|
232
|
+
environment: this.environment.getState(),
|
|
233
|
+
status: this.status,
|
|
234
|
+
stopped: this.stopped,
|
|
235
|
+
counters: this.counters,
|
|
236
|
+
broker: this.broker.getState(true),
|
|
237
|
+
execution: this.execution && this.execution.getState(),
|
|
238
|
+
output: { ...this.environment.output
|
|
329
239
|
}
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
proto.cancelActivity = function cancelActivity(message) {
|
|
244
|
+
return this.getApi().cancel(message, {
|
|
245
|
+
delegate: true
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
proto._activateRunConsumers = function activateRunConsumers() {
|
|
250
|
+
this[consumingSymbol] = true;
|
|
251
|
+
const broker = this.broker;
|
|
252
|
+
const {
|
|
253
|
+
onApiMessage,
|
|
254
|
+
onRunMessage
|
|
255
|
+
} = this[messageHandlersSymbol];
|
|
256
|
+
broker.subscribeTmp('api', `process.*.${this.executionId}`, onApiMessage, {
|
|
257
|
+
noAck: true,
|
|
258
|
+
consumerTag: '_process-api',
|
|
259
|
+
priority: 100
|
|
260
|
+
});
|
|
261
|
+
broker.getQueue('run-q').assertConsumer(onRunMessage, {
|
|
262
|
+
exclusive: true,
|
|
263
|
+
consumerTag: '_process-run'
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
proto._deactivateRunConsumers = function deactivateRunConsumers() {
|
|
268
|
+
const broker = this.broker;
|
|
269
|
+
broker.cancel('_process-api');
|
|
270
|
+
broker.cancel('_process-run');
|
|
271
|
+
broker.cancel('_process-execution');
|
|
272
|
+
this[consumingSymbol] = false;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
proto._onRunMessage = function onRunMessage(routingKey, message) {
|
|
276
|
+
const {
|
|
277
|
+
content,
|
|
278
|
+
fields
|
|
279
|
+
} = message;
|
|
280
|
+
|
|
281
|
+
if (routingKey === 'run.resume') {
|
|
282
|
+
return this._onResumeMessage(message);
|
|
330
283
|
}
|
|
331
284
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
const messageType = message.properties.type;
|
|
335
|
-
message.ack();
|
|
285
|
+
const exec = this[execSymbol];
|
|
286
|
+
this[stateMessageSymbol] = message;
|
|
336
287
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
}
|
|
288
|
+
switch (routingKey) {
|
|
289
|
+
case 'run.enter':
|
|
290
|
+
{
|
|
291
|
+
this._debug('enter');
|
|
342
292
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
}
|
|
293
|
+
this[statusSymbol] = 'entered';
|
|
294
|
+
if (fields.redelivered) break;
|
|
295
|
+
exec.execution = undefined;
|
|
296
|
+
|
|
297
|
+
this._publishEvent('enter', content);
|
|
349
298
|
|
|
350
|
-
case 'discard':
|
|
351
|
-
broker.publish('run', 'run.discarded', content);
|
|
352
299
|
break;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
case 'run.start':
|
|
303
|
+
{
|
|
304
|
+
this._debug('start');
|
|
305
|
+
|
|
306
|
+
this[statusSymbol] = 'start';
|
|
353
307
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
308
|
+
this._publishEvent('start', content);
|
|
309
|
+
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
case 'run.execute':
|
|
314
|
+
{
|
|
315
|
+
this[statusSymbol] = 'executing';
|
|
316
|
+
const executeMessage = (0, _messageHelper.cloneMessage)(message);
|
|
317
|
+
|
|
318
|
+
if (fields.redelivered && !exec.execution) {
|
|
319
|
+
executeMessage.fields.redelivered = undefined;
|
|
357
320
|
}
|
|
358
|
-
}
|
|
359
321
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
322
|
+
this[executeMessageSymbol] = message;
|
|
323
|
+
this.broker.getQueue('execution-q').assertConsumer(this[messageHandlersSymbol].onExecutionMessage, {
|
|
324
|
+
exclusive: true,
|
|
325
|
+
consumerTag: '_process-execution'
|
|
326
|
+
});
|
|
327
|
+
const execution = exec.execution = exec.execution || new _ProcessExecution.default(this, this.context);
|
|
328
|
+
return execution.execute(executeMessage);
|
|
329
|
+
}
|
|
366
330
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
type: state,
|
|
373
|
-
mandatory: state === 'error'
|
|
374
|
-
});
|
|
375
|
-
}
|
|
331
|
+
case 'run.error':
|
|
332
|
+
{
|
|
333
|
+
this._publishEvent('error', (0, _messageHelper.cloneContent)(content, {
|
|
334
|
+
error: fields.redelivered ? (0, _Errors.makeErrorFromMessage)(message) : content.error
|
|
335
|
+
}));
|
|
376
336
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
if (!messageContent) return;
|
|
380
|
-
let targetsFound = false;
|
|
381
|
-
|
|
382
|
-
if (messageContent.target && messageContent.target.id && getActivityById(messageContent.target.id)) {
|
|
383
|
-
targetsFound = true;
|
|
384
|
-
} else if (messageContent.message && getStartActivities({
|
|
385
|
-
referenceId: messageContent.message.id,
|
|
386
|
-
referenceType: messageContent.message.messageType
|
|
387
|
-
}).length) {
|
|
388
|
-
targetsFound = true;
|
|
389
|
-
}
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
390
339
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
});
|
|
396
|
-
}
|
|
340
|
+
case 'run.end':
|
|
341
|
+
{
|
|
342
|
+
this[statusSymbol] = 'end';
|
|
343
|
+
if (fields.redelivered) break;
|
|
397
344
|
|
|
398
|
-
|
|
399
|
-
if (execution) return execution.getActivityById(childId);
|
|
400
|
-
return context.getActivityById(childId);
|
|
401
|
-
}
|
|
345
|
+
this._debug('completed');
|
|
402
346
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
return context.getActivities(id);
|
|
406
|
-
}
|
|
347
|
+
this[countersSymbol].completed++;
|
|
348
|
+
this.broker.publish('run', 'run.leave', content);
|
|
407
349
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
350
|
+
this._publishEvent('end', content);
|
|
351
|
+
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
case 'run.discarded':
|
|
356
|
+
{
|
|
357
|
+
this[statusSymbol] = 'discarded';
|
|
358
|
+
if (fields.redelivered) break;
|
|
359
|
+
this[countersSymbol].discarded++;
|
|
360
|
+
this.broker.publish('run', 'run.leave', content);
|
|
361
|
+
|
|
362
|
+
this._publishEvent('discarded', content);
|
|
363
|
+
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
case 'run.leave':
|
|
368
|
+
{
|
|
369
|
+
this[statusSymbol] = undefined;
|
|
370
|
+
this.broker.cancel('_process-api');
|
|
371
|
+
const {
|
|
372
|
+
output,
|
|
373
|
+
...rest
|
|
374
|
+
} = content; // eslint-disable-line no-unused-vars
|
|
375
|
+
|
|
376
|
+
this._publishEvent('leave', rest);
|
|
411
377
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
return context.getSequenceFlows();
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
415
380
|
}
|
|
416
381
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
382
|
+
message.ack();
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
proto._onResumeMessage = function onResumeMessage(message) {
|
|
386
|
+
message.ack();
|
|
387
|
+
const stateMessage = this[stateMessageSymbol];
|
|
388
|
+
|
|
389
|
+
switch (stateMessage.fields.routingKey) {
|
|
390
|
+
case 'run.enter':
|
|
391
|
+
case 'run.start':
|
|
392
|
+
case 'run.discarded':
|
|
393
|
+
case 'run.end':
|
|
394
|
+
case 'run.leave':
|
|
395
|
+
break;
|
|
396
|
+
|
|
397
|
+
default:
|
|
398
|
+
return;
|
|
420
399
|
}
|
|
421
400
|
|
|
422
|
-
|
|
423
|
-
const messageType = message.properties.type;
|
|
401
|
+
if (!stateMessage.fields.redelivered) return;
|
|
424
402
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
403
|
+
this._debug(`resume from ${this.status}`);
|
|
404
|
+
|
|
405
|
+
return this.broker.publish('run', stateMessage.fields.routingKey, (0, _messageHelper.cloneContent)(stateMessage.content), stateMessage.properties);
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
proto._onExecutionMessage = function onExecutionMessage(routingKey, message) {
|
|
409
|
+
const content = message.content;
|
|
410
|
+
const messageType = message.properties.type;
|
|
411
|
+
message.ack();
|
|
412
|
+
|
|
413
|
+
switch (messageType) {
|
|
414
|
+
case 'stopped':
|
|
415
|
+
{
|
|
416
|
+
return this._onStop();
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
case 'error':
|
|
420
|
+
{
|
|
421
|
+
this.broker.publish('run', 'run.error', content);
|
|
422
|
+
this.broker.publish('run', 'run.discarded', content);
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
case 'discard':
|
|
427
|
+
this.broker.publish('run', 'run.discarded', content);
|
|
428
|
+
break;
|
|
429
|
+
|
|
430
|
+
default:
|
|
431
|
+
{
|
|
432
|
+
this.broker.publish('run', 'run.end', content);
|
|
433
|
+
}
|
|
433
434
|
}
|
|
434
435
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
436
|
+
const executeMessage = this[executeMessageSymbol];
|
|
437
|
+
|
|
438
|
+
if (executeMessage) {
|
|
439
|
+
this[executeMessageSymbol] = null;
|
|
440
|
+
executeMessage.ack();
|
|
439
441
|
}
|
|
442
|
+
};
|
|
440
443
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
444
|
+
proto._publishEvent = function publishEvent(state, content) {
|
|
445
|
+
const eventContent = this._createMessage({ ...content,
|
|
446
|
+
state
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
this.broker.publish('event', `process.${state}`, eventContent, {
|
|
450
|
+
type: state,
|
|
451
|
+
mandatory: state === 'error'
|
|
452
|
+
});
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
proto.sendMessage = function sendMessage(message) {
|
|
456
|
+
const messageContent = message.content;
|
|
457
|
+
if (!messageContent) return;
|
|
458
|
+
let targetsFound = false;
|
|
459
|
+
|
|
460
|
+
if (messageContent.target && messageContent.target.id && this.getActivityById(messageContent.target.id)) {
|
|
461
|
+
targetsFound = true;
|
|
462
|
+
} else if (messageContent.message && this.getStartActivities({
|
|
463
|
+
referenceId: messageContent.message.id,
|
|
464
|
+
referenceType: messageContent.message.messageType
|
|
465
|
+
}).length) {
|
|
466
|
+
targetsFound = true;
|
|
450
467
|
}
|
|
451
468
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
469
|
+
if (!targetsFound) return;
|
|
470
|
+
if (!this.status) this.run();
|
|
471
|
+
this.getApi().sendApiMessage(message.properties.type || 'message', (0, _messageHelper.cloneContent)(messageContent), {
|
|
472
|
+
delegate: true
|
|
473
|
+
});
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
proto.getActivityById = function getActivityById(childId) {
|
|
477
|
+
if (this.execution) return this.execution.getActivityById(childId);
|
|
478
|
+
return this.context.getActivityById(childId);
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
proto.getActivities = function getActivities() {
|
|
482
|
+
if (this.execution) return this.execution.getActivities();
|
|
483
|
+
return this.context.getActivities(this.id);
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
proto.getStartActivities = function getStartActivities(filterOptions) {
|
|
487
|
+
return this.context.getStartActivities(filterOptions, this.id);
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
proto.getSequenceFlows = function getSequenceFlows() {
|
|
491
|
+
if (this.execution) return this.execution.getSequenceFlows();
|
|
492
|
+
return this.context.getSequenceFlows();
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
proto.getPostponed = function getPostponed(...args) {
|
|
496
|
+
if (!this.execution) return [];
|
|
497
|
+
return this.execution.getPostponed(...args);
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
proto._onApiMessage = function onApiMessage(routingKey, message) {
|
|
501
|
+
const messageType = message.properties.type;
|
|
502
|
+
|
|
503
|
+
switch (messageType) {
|
|
504
|
+
case 'stop':
|
|
505
|
+
{
|
|
506
|
+
if (this.execution && !this.execution.completed) return;
|
|
507
|
+
|
|
508
|
+
this._onStop();
|
|
509
|
+
|
|
510
|
+
break;
|
|
511
|
+
}
|
|
462
512
|
}
|
|
463
|
-
}
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
proto._onStop = function onStop() {
|
|
516
|
+
this[stoppedSymbol] = true;
|
|
517
|
+
|
|
518
|
+
this._deactivateRunConsumers();
|
|
519
|
+
|
|
520
|
+
return this._publishEvent('stop');
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
proto._createMessage = function createMessage(override) {
|
|
524
|
+
return {
|
|
525
|
+
id: this.id,
|
|
526
|
+
type: this.type,
|
|
527
|
+
name: this.name,
|
|
528
|
+
executionId: this.executionId,
|
|
529
|
+
parent: { ...this.parent
|
|
530
|
+
},
|
|
531
|
+
...override
|
|
532
|
+
};
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
proto._debug = function debug(msg) {
|
|
536
|
+
this.logger.debug(`<${this.id}> ${msg}`);
|
|
537
|
+
};
|