bpmn-elements 8.1.0 → 8.2.1
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 +10 -0
- package/dist/index.js +0 -49
- package/dist/src/Api.js +4 -19
- package/dist/src/Context.js +7 -36
- package/dist/src/Environment.js +18 -44
- package/dist/src/EventBroker.js +8 -27
- package/dist/src/Expressions.js +0 -13
- package/dist/src/ExtensionsMapper.js +32 -44
- package/dist/src/MessageFormatter.js +0 -33
- package/dist/src/Scripts.js +2 -9
- package/dist/src/Timers.js +0 -9
- package/dist/src/activity/Activity.js +62 -294
- package/dist/src/activity/ActivityExecution.js +8 -76
- package/dist/src/activity/Dummy.js +2 -3
- package/dist/src/activity/Escalation.js +4 -4
- package/dist/src/activity/ExecutionScope.js +0 -4
- package/dist/src/activity/Message.js +4 -4
- package/dist/src/activity/Signal.js +4 -4
- package/dist/src/definition/Definition.js +12 -133
- package/dist/src/definition/DefinitionExecution.js +10 -160
- package/dist/src/error/BpmnError.js +2 -3
- package/dist/src/error/Errors.js +0 -16
- package/dist/src/eventDefinitions/CancelEventDefinition.js +2 -35
- package/dist/src/eventDefinitions/CompensateEventDefinition.js +3 -34
- package/dist/src/eventDefinitions/ConditionalEventDefinition.js +3 -42
- package/dist/src/eventDefinitions/ErrorEventDefinition.js +11 -41
- package/dist/src/eventDefinitions/EscalationEventDefinition.js +7 -37
- package/dist/src/eventDefinitions/EventDefinitionExecution.js +0 -30
- package/dist/src/eventDefinitions/LinkEventDefinition.js +11 -37
- package/dist/src/eventDefinitions/MessageEventDefinition.js +11 -44
- package/dist/src/eventDefinitions/SignalEventDefinition.js +9 -46
- package/dist/src/eventDefinitions/TerminateEventDefinition.js +0 -3
- package/dist/src/eventDefinitions/TimerEventDefinition.js +8 -52
- package/dist/src/events/BoundaryEvent.js +4 -44
- package/dist/src/events/EndEvent.js +2 -11
- package/dist/src/events/IntermediateCatchEvent.js +0 -13
- package/dist/src/events/IntermediateThrowEvent.js +2 -11
- package/dist/src/events/StartEvent.js +5 -25
- package/dist/src/flows/Association.js +4 -27
- package/dist/src/flows/MessageFlow.js +6 -18
- package/dist/src/flows/SequenceFlow.js +4 -39
- package/dist/src/gateways/EventBasedGateway.js +0 -21
- package/dist/src/gateways/ExclusiveGateway.js +0 -6
- package/dist/src/gateways/InclusiveGateway.js +0 -6
- package/dist/src/gateways/ParallelGateway.js +2 -7
- package/dist/src/getPropertyValue.js +0 -30
- package/dist/src/io/BpmnIO.js +8 -5
- package/dist/src/io/EnvironmentDataObject.js +0 -8
- package/dist/src/io/EnvironmentDataStore.js +0 -8
- package/dist/src/io/EnvironmentDataStoreReference.js +0 -8
- package/dist/src/io/InputOutputSpecification.js +25 -36
- package/dist/src/io/Properties.js +15 -47
- package/dist/src/messageHelper.js +10 -23
- package/dist/src/process/Process.js +10 -112
- package/dist/src/process/ProcessExecution.js +14 -170
- package/dist/src/shared.js +0 -7
- package/dist/src/tasks/CallActivity.js +2 -23
- package/dist/src/tasks/LoopCharacteristics.js +16 -67
- package/dist/src/tasks/ReceiveTask.js +8 -48
- package/dist/src/tasks/ScriptTask.js +1 -15
- package/dist/src/tasks/ServiceImplementation.js +0 -4
- package/dist/src/tasks/ServiceTask.js +1 -25
- package/dist/src/tasks/SignalTask.js +2 -21
- package/dist/src/tasks/StandardLoopCharacteristics.js +4 -5
- package/dist/src/tasks/SubProcess.js +4 -52
- package/dist/src/tasks/Task.js +0 -8
- package/dist/src/tasks/Transaction.js +0 -3
- package/package.json +8 -8
- package/src/Context.js +7 -3
- package/src/ExtensionsMapper.js +35 -35
- package/src/activity/Activity.js +22 -51
- package/src/gateways/EventBasedGateway.js +0 -1
- package/src/io/BpmnIO.js +7 -0
- package/src/io/EnvironmentDataObject.js +1 -0
- package/src/io/InputOutputSpecification.js +17 -6
- package/src/io/Properties.js +9 -11
- package/src/process/ProcessExecution.js +2 -1
- package/src/tasks/ServiceTask.js +1 -3
- package/src/tasks/StandardLoopCharacteristics.js +0 -1
|
@@ -5,21 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.Definition = Definition;
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
|
|
9
8
|
var _DefinitionExecution = _interopRequireDefault(require("./DefinitionExecution"));
|
|
10
|
-
|
|
11
9
|
var _Api = require("../Api");
|
|
12
|
-
|
|
13
10
|
var _EventBroker = require("../EventBroker");
|
|
14
|
-
|
|
15
11
|
var _shared = require("../shared");
|
|
16
|
-
|
|
17
12
|
var _Errors = require("../error/Errors");
|
|
18
|
-
|
|
19
13
|
var _messageHelper = require("../messageHelper");
|
|
20
|
-
|
|
21
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
-
|
|
23
15
|
const kConsuming = Symbol.for('consuming');
|
|
24
16
|
const kCounters = Symbol.for('counters');
|
|
25
17
|
const kExec = Symbol.for('execution');
|
|
@@ -30,7 +22,6 @@ const kStatus = Symbol.for('status');
|
|
|
30
22
|
const kStopped = Symbol.for('stopped');
|
|
31
23
|
var _default = Definition;
|
|
32
24
|
exports.default = _default;
|
|
33
|
-
|
|
34
25
|
function Definition(context, options) {
|
|
35
26
|
if (!(this instanceof Definition)) return new Definition(context, options);
|
|
36
27
|
if (!context) throw new Error('No context');
|
|
@@ -43,7 +34,6 @@ function Definition(context, options) {
|
|
|
43
34
|
this.type = type;
|
|
44
35
|
this.name = name;
|
|
45
36
|
let environment;
|
|
46
|
-
|
|
47
37
|
if (options) {
|
|
48
38
|
environment = this.environment = context.environment.clone(options);
|
|
49
39
|
this.context = context.clone(environment);
|
|
@@ -51,16 +41,13 @@ function Definition(context, options) {
|
|
|
51
41
|
environment = this.environment = context.environment;
|
|
52
42
|
this.context = context;
|
|
53
43
|
}
|
|
54
|
-
|
|
55
44
|
this[kCounters] = {
|
|
56
45
|
completed: 0,
|
|
57
46
|
discarded: 0
|
|
58
47
|
};
|
|
59
48
|
this[kStopped] = false;
|
|
60
49
|
this[kExec] = {};
|
|
61
|
-
|
|
62
50
|
const onBrokerReturn = this._onBrokerReturnFn.bind(this);
|
|
63
|
-
|
|
64
51
|
this[kMessageHandlers] = {
|
|
65
52
|
onBrokerReturn,
|
|
66
53
|
onApiMessage: this._onApiMessage.bind(this),
|
|
@@ -83,116 +70,88 @@ function Definition(context, options) {
|
|
|
83
70
|
this.emitFatal = emitFatal;
|
|
84
71
|
this.logger = environment.Logger(type.toLowerCase());
|
|
85
72
|
}
|
|
86
|
-
|
|
87
73
|
const proto = Definition.prototype;
|
|
88
74
|
Object.defineProperty(proto, 'counters', {
|
|
89
75
|
enumerable: true,
|
|
90
|
-
|
|
91
76
|
get() {
|
|
92
|
-
return {
|
|
77
|
+
return {
|
|
78
|
+
...this[kCounters]
|
|
93
79
|
};
|
|
94
80
|
}
|
|
95
|
-
|
|
96
81
|
});
|
|
97
82
|
Object.defineProperty(proto, 'execution', {
|
|
98
83
|
enumerable: true,
|
|
99
|
-
|
|
100
84
|
get() {
|
|
101
85
|
return this[kExec].execution;
|
|
102
86
|
}
|
|
103
|
-
|
|
104
87
|
});
|
|
105
88
|
Object.defineProperty(proto, 'executionId', {
|
|
106
89
|
enumerable: true,
|
|
107
|
-
|
|
108
90
|
get() {
|
|
109
91
|
return this[kExec].executionId;
|
|
110
92
|
}
|
|
111
|
-
|
|
112
93
|
});
|
|
113
94
|
Object.defineProperty(proto, 'isRunning', {
|
|
114
95
|
enumerable: true,
|
|
115
|
-
|
|
116
96
|
get() {
|
|
117
97
|
if (!this[kConsuming]) return false;
|
|
118
98
|
return !!this.status;
|
|
119
99
|
}
|
|
120
|
-
|
|
121
100
|
});
|
|
122
101
|
Object.defineProperty(proto, 'status', {
|
|
123
102
|
enumerable: true,
|
|
124
|
-
|
|
125
103
|
get() {
|
|
126
104
|
return this[kStatus];
|
|
127
105
|
}
|
|
128
|
-
|
|
129
106
|
});
|
|
130
107
|
Object.defineProperty(proto, 'stopped', {
|
|
131
108
|
enumerable: true,
|
|
132
|
-
|
|
133
109
|
get() {
|
|
134
110
|
return this[kStopped];
|
|
135
111
|
}
|
|
136
|
-
|
|
137
112
|
});
|
|
138
|
-
|
|
139
113
|
proto.run = function run(optionsOrCallback, optionalCallback) {
|
|
140
114
|
const [runOptions, callback] = (0, _shared.getOptionsAndCallback)(optionsOrCallback, optionalCallback);
|
|
141
|
-
|
|
142
115
|
if (this.isRunning) {
|
|
143
116
|
const err = new Error('definition is already running');
|
|
144
117
|
if (callback) return callback(err);
|
|
145
118
|
throw err;
|
|
146
119
|
}
|
|
147
|
-
|
|
148
120
|
if (callback) {
|
|
149
121
|
addConsumerCallbacks(this, callback);
|
|
150
122
|
}
|
|
151
|
-
|
|
152
123
|
const exec = this[kExec];
|
|
153
124
|
exec.executionId = (0, _shared.getUniqueId)(this.id);
|
|
154
|
-
|
|
155
|
-
|
|
125
|
+
const content = this._createMessage({
|
|
126
|
+
...runOptions
|
|
156
127
|
});
|
|
157
|
-
|
|
158
128
|
const broker = this.broker;
|
|
159
129
|
broker.publish('run', 'run.enter', content);
|
|
160
130
|
broker.publish('run', 'run.start', (0, _messageHelper.cloneContent)(content));
|
|
161
131
|
broker.publish('run', 'run.execute', (0, _messageHelper.cloneContent)(content));
|
|
162
132
|
this.logger.debug(`<${this.executionId} (${this.id})> run`);
|
|
163
|
-
|
|
164
133
|
this._activateRunConsumers();
|
|
165
|
-
|
|
166
134
|
return this;
|
|
167
135
|
};
|
|
168
|
-
|
|
169
136
|
proto.resume = function resume(callback) {
|
|
170
137
|
if (this.isRunning) {
|
|
171
138
|
const err = new Error('cannot resume running definition');
|
|
172
139
|
if (callback) return callback(err);
|
|
173
140
|
throw err;
|
|
174
141
|
}
|
|
175
|
-
|
|
176
142
|
this[kStopped] = false;
|
|
177
143
|
if (!this.status) return this;
|
|
178
|
-
|
|
179
144
|
if (callback) {
|
|
180
145
|
addConsumerCallbacks(this, callback);
|
|
181
146
|
}
|
|
182
|
-
|
|
183
147
|
this.logger.debug(`<${this.executionId} (${this.id})> resume`);
|
|
184
|
-
|
|
185
148
|
const content = this._createMessage();
|
|
186
|
-
|
|
187
149
|
this.broker.publish('run', 'run.resume', content, {
|
|
188
150
|
persistent: false
|
|
189
151
|
});
|
|
190
|
-
|
|
191
152
|
this._activateRunConsumers();
|
|
192
|
-
|
|
193
153
|
return this;
|
|
194
154
|
};
|
|
195
|
-
|
|
196
155
|
proto.recover = function recover(state) {
|
|
197
156
|
if (this.isRunning) throw new Error('cannot recover running definition');
|
|
198
157
|
if (!state) return this;
|
|
@@ -200,28 +159,23 @@ proto.recover = function recover(state) {
|
|
|
200
159
|
this[kStatus] = state.status;
|
|
201
160
|
const exec = this[kExec];
|
|
202
161
|
exec.executionId = state.executionId;
|
|
203
|
-
|
|
204
162
|
if (state.counters) {
|
|
205
|
-
this[kCounters] = {
|
|
163
|
+
this[kCounters] = {
|
|
164
|
+
...this[kCounters],
|
|
206
165
|
...state.counters
|
|
207
166
|
};
|
|
208
167
|
}
|
|
209
|
-
|
|
210
168
|
this.environment.recover(state.environment);
|
|
211
|
-
|
|
212
169
|
if (state.execution) {
|
|
213
170
|
exec.execution = new _DefinitionExecution.default(this, this.context).recover(state.execution);
|
|
214
171
|
}
|
|
215
|
-
|
|
216
172
|
this.broker.recover(state.broker);
|
|
217
173
|
return this;
|
|
218
174
|
};
|
|
219
|
-
|
|
220
175
|
proto.shake = function shake(startId) {
|
|
221
176
|
let result = {};
|
|
222
177
|
const broker = this.broker;
|
|
223
178
|
let bps;
|
|
224
|
-
|
|
225
179
|
if (startId) {
|
|
226
180
|
const startActivity = this.getActivityById(startId);
|
|
227
181
|
if (!startActivity) return;
|
|
@@ -229,13 +183,10 @@ proto.shake = function shake(startId) {
|
|
|
229
183
|
if (!bp) return;
|
|
230
184
|
bps = [bp];
|
|
231
185
|
} else bps = this.getProcesses();
|
|
232
|
-
|
|
233
186
|
bps.forEach(shakeProcess);
|
|
234
187
|
return result;
|
|
235
|
-
|
|
236
188
|
function shakeProcess(shakeBp) {
|
|
237
189
|
let shovel;
|
|
238
|
-
|
|
239
190
|
if (!shakeBp.isRunning) {
|
|
240
191
|
shovel = shakeBp.broker.createShovel('shaker', {
|
|
241
192
|
exchange: 'event',
|
|
@@ -245,15 +196,14 @@ proto.shake = function shake(startId) {
|
|
|
245
196
|
exchange: 'event'
|
|
246
197
|
});
|
|
247
198
|
}
|
|
248
|
-
|
|
249
199
|
const shakeResult = shakeBp.shake(startId);
|
|
250
200
|
if (shovel) shakeBp.broker.closeShovel('shaker');
|
|
251
|
-
result = {
|
|
201
|
+
result = {
|
|
202
|
+
...result,
|
|
252
203
|
...shakeResult
|
|
253
204
|
};
|
|
254
205
|
}
|
|
255
206
|
};
|
|
256
|
-
|
|
257
207
|
proto.getState = function getState() {
|
|
258
208
|
return this._createMessage({
|
|
259
209
|
status: this.status,
|
|
@@ -264,50 +214,40 @@ proto.getState = function getState() {
|
|
|
264
214
|
broker: this.broker.getState(true)
|
|
265
215
|
});
|
|
266
216
|
};
|
|
267
|
-
|
|
268
217
|
proto.getProcesses = function getProcesses() {
|
|
269
218
|
const execution = this.execution;
|
|
270
219
|
if (execution) return execution.getProcesses();
|
|
271
220
|
return this.context.getProcesses();
|
|
272
221
|
};
|
|
273
|
-
|
|
274
222
|
proto.getExecutableProcesses = function getExecutableProcesses() {
|
|
275
223
|
const execution = this.execution;
|
|
276
224
|
if (execution) return execution.getExecutableProcesses();
|
|
277
225
|
return this.context.getExecutableProcesses();
|
|
278
226
|
};
|
|
279
|
-
|
|
280
227
|
proto.getRunningProcesses = function getRunningProcesses() {
|
|
281
228
|
const execution = this.execution;
|
|
282
229
|
if (!execution) return [];
|
|
283
230
|
return execution.getRunningProcesses();
|
|
284
231
|
};
|
|
285
|
-
|
|
286
232
|
proto.getProcessById = function getProcessById(processId) {
|
|
287
233
|
return this.getProcesses().find(p => p.id === processId);
|
|
288
234
|
};
|
|
289
|
-
|
|
290
235
|
proto.getActivityById = function getActivityById(childId) {
|
|
291
236
|
const bps = this.getProcesses();
|
|
292
|
-
|
|
293
237
|
for (const bp of bps) {
|
|
294
238
|
const child = bp.getActivityById(childId);
|
|
295
239
|
if (child) return child;
|
|
296
240
|
}
|
|
297
|
-
|
|
298
241
|
return null;
|
|
299
242
|
};
|
|
300
|
-
|
|
301
243
|
proto.getElementById = function getElementById(elementId) {
|
|
302
244
|
return this.context.getActivityById(elementId);
|
|
303
245
|
};
|
|
304
|
-
|
|
305
246
|
proto.getPostponed = function getPostponed(...args) {
|
|
306
247
|
const execution = this.execution;
|
|
307
248
|
if (!execution) return [];
|
|
308
249
|
return execution.getPostponed(...args);
|
|
309
250
|
};
|
|
310
|
-
|
|
311
251
|
proto.getApi = function getApi(message) {
|
|
312
252
|
const execution = this.execution;
|
|
313
253
|
if (execution) return execution.getApi(message);
|
|
@@ -315,46 +255,40 @@ proto.getApi = function getApi(message) {
|
|
|
315
255
|
if (!message) throw new Error('Definition is not running');
|
|
316
256
|
return (0, _Api.DefinitionApi)(this.broker, message);
|
|
317
257
|
};
|
|
318
|
-
|
|
319
258
|
proto.signal = function signal(message) {
|
|
320
259
|
return this.getApi().signal(message, {
|
|
321
260
|
delegate: true
|
|
322
261
|
});
|
|
323
262
|
};
|
|
324
|
-
|
|
325
263
|
proto.cancelActivity = function cancelActivity(message) {
|
|
326
264
|
return this.getApi().cancel(message, {
|
|
327
265
|
delegate: true
|
|
328
266
|
});
|
|
329
267
|
};
|
|
330
|
-
|
|
331
268
|
proto.sendMessage = function sendMessage(message) {
|
|
332
269
|
const messageContent = {
|
|
333
270
|
message
|
|
334
271
|
};
|
|
335
272
|
let messageType = 'message';
|
|
336
273
|
const reference = message && message.id && this.getElementById(message.id);
|
|
337
|
-
|
|
338
274
|
if (reference && reference.resolve) {
|
|
339
275
|
const resolvedReference = reference.resolve(this._createMessage({
|
|
340
276
|
message
|
|
341
277
|
}));
|
|
342
278
|
messageType = resolvedReference.messageType || messageType;
|
|
343
|
-
messageContent.message = {
|
|
279
|
+
messageContent.message = {
|
|
280
|
+
...message,
|
|
344
281
|
...resolvedReference
|
|
345
282
|
};
|
|
346
283
|
}
|
|
347
|
-
|
|
348
284
|
return this.getApi().sendApiMessage(messageType, messageContent, {
|
|
349
285
|
delegate: true
|
|
350
286
|
});
|
|
351
287
|
};
|
|
352
|
-
|
|
353
288
|
proto.stop = function stop() {
|
|
354
289
|
if (!this.isRunning) return;
|
|
355
290
|
this.getApi().stop();
|
|
356
291
|
};
|
|
357
|
-
|
|
358
292
|
proto._activateRunConsumers = function activateRunConsumers() {
|
|
359
293
|
this[kConsuming] = true;
|
|
360
294
|
const broker = this.broker;
|
|
@@ -371,7 +305,6 @@ proto._activateRunConsumers = function activateRunConsumers() {
|
|
|
371
305
|
consumerTag: '_definition-run'
|
|
372
306
|
});
|
|
373
307
|
};
|
|
374
|
-
|
|
375
308
|
proto._deactivateRunConsumers = function deactivateRunConsumers() {
|
|
376
309
|
const broker = this.broker;
|
|
377
310
|
broker.cancel('_definition-api');
|
|
@@ -379,7 +312,6 @@ proto._deactivateRunConsumers = function deactivateRunConsumers() {
|
|
|
379
312
|
broker.cancel('_definition-execution');
|
|
380
313
|
this[kConsuming] = false;
|
|
381
314
|
};
|
|
382
|
-
|
|
383
315
|
proto._createMessage = function createMessage(override) {
|
|
384
316
|
return {
|
|
385
317
|
id: this.id,
|
|
@@ -389,20 +321,16 @@ proto._createMessage = function createMessage(override) {
|
|
|
389
321
|
...override
|
|
390
322
|
};
|
|
391
323
|
};
|
|
392
|
-
|
|
393
324
|
proto._onRunMessage = function onRunMessage(routingKey, message) {
|
|
394
325
|
const {
|
|
395
326
|
content,
|
|
396
327
|
fields
|
|
397
328
|
} = message;
|
|
398
|
-
|
|
399
329
|
if (routingKey === 'run.resume') {
|
|
400
330
|
return this._onResumeMessage(message);
|
|
401
331
|
}
|
|
402
|
-
|
|
403
332
|
const exec = this[kExec];
|
|
404
333
|
this[kStateMessage] = message;
|
|
405
|
-
|
|
406
334
|
switch (routingKey) {
|
|
407
335
|
case 'run.enter':
|
|
408
336
|
{
|
|
@@ -410,45 +338,34 @@ proto._onRunMessage = function onRunMessage(routingKey, message) {
|
|
|
410
338
|
this[kStatus] = 'entered';
|
|
411
339
|
if (fields.redelivered) break;
|
|
412
340
|
exec.execution = undefined;
|
|
413
|
-
|
|
414
341
|
this._publishEvent('enter', content);
|
|
415
|
-
|
|
416
342
|
break;
|
|
417
343
|
}
|
|
418
|
-
|
|
419
344
|
case 'run.start':
|
|
420
345
|
{
|
|
421
346
|
this.logger.debug(`<${this.executionId} (${this.id})> start`);
|
|
422
347
|
this[kStatus] = 'start';
|
|
423
|
-
|
|
424
348
|
this._publishEvent('start', content);
|
|
425
|
-
|
|
426
349
|
break;
|
|
427
350
|
}
|
|
428
|
-
|
|
429
351
|
case 'run.execute':
|
|
430
352
|
{
|
|
431
353
|
this[kStatus] = 'executing';
|
|
432
354
|
const executeMessage = (0, _messageHelper.cloneMessage)(message);
|
|
433
|
-
|
|
434
355
|
if (fields.redelivered && !exec.execution) {
|
|
435
356
|
executeMessage.fields.redelivered = undefined;
|
|
436
357
|
}
|
|
437
|
-
|
|
438
358
|
this[kExecuteMessage] = message;
|
|
439
359
|
this.broker.getQueue('execution-q').assertConsumer(this[kMessageHandlers].onExecutionMessage, {
|
|
440
360
|
exclusive: true,
|
|
441
361
|
consumerTag: '_definition-execution'
|
|
442
362
|
});
|
|
443
363
|
exec.execution = exec.execution || new _DefinitionExecution.default(this, this.context);
|
|
444
|
-
|
|
445
364
|
if (executeMessage.fields.redelivered) {
|
|
446
365
|
this._publishEvent('resume', content);
|
|
447
366
|
}
|
|
448
|
-
|
|
449
367
|
return exec.execution.execute(executeMessage);
|
|
450
368
|
}
|
|
451
|
-
|
|
452
369
|
case 'run.end':
|
|
453
370
|
{
|
|
454
371
|
if (this[kStatus] === 'end') break;
|
|
@@ -456,23 +373,19 @@ proto._onRunMessage = function onRunMessage(routingKey, message) {
|
|
|
456
373
|
this.logger.debug(`<${this.executionId} (${this.id})> completed`);
|
|
457
374
|
this[kStatus] = 'end';
|
|
458
375
|
this.broker.publish('run', 'run.leave', content);
|
|
459
|
-
|
|
460
376
|
this._publishEvent('end', content);
|
|
461
|
-
|
|
462
377
|
break;
|
|
463
378
|
}
|
|
464
|
-
|
|
465
379
|
case 'run.error':
|
|
466
380
|
{
|
|
467
|
-
this._publishEvent('error', {
|
|
381
|
+
this._publishEvent('error', {
|
|
382
|
+
...content,
|
|
468
383
|
error: fields.redelivered ? (0, _Errors.makeErrorFromMessage)(message) : content.error
|
|
469
384
|
}, {
|
|
470
385
|
mandatory: true
|
|
471
386
|
});
|
|
472
|
-
|
|
473
387
|
break;
|
|
474
388
|
}
|
|
475
|
-
|
|
476
389
|
case 'run.discarded':
|
|
477
390
|
{
|
|
478
391
|
if (this[kStatus] === 'discarded') break;
|
|
@@ -481,44 +394,32 @@ proto._onRunMessage = function onRunMessage(routingKey, message) {
|
|
|
481
394
|
this.broker.publish('run', 'run.leave', content);
|
|
482
395
|
break;
|
|
483
396
|
}
|
|
484
|
-
|
|
485
397
|
case 'run.leave':
|
|
486
398
|
{
|
|
487
399
|
message.ack();
|
|
488
400
|
this[kStatus] = undefined;
|
|
489
|
-
|
|
490
401
|
this._deactivateRunConsumers();
|
|
491
|
-
|
|
492
402
|
this._publishEvent('leave', this._createMessage());
|
|
493
|
-
|
|
494
403
|
return;
|
|
495
404
|
}
|
|
496
405
|
}
|
|
497
|
-
|
|
498
406
|
message.ack();
|
|
499
407
|
};
|
|
500
|
-
|
|
501
408
|
proto._onResumeMessage = function onResumeMessage(message) {
|
|
502
409
|
message.ack();
|
|
503
410
|
const stateMessage = this[kStateMessage];
|
|
504
|
-
|
|
505
411
|
switch (stateMessage.fields.routingKey) {
|
|
506
412
|
case 'run.discarded':
|
|
507
413
|
case 'run.end':
|
|
508
414
|
case 'run.leave':
|
|
509
415
|
break;
|
|
510
|
-
|
|
511
416
|
default:
|
|
512
417
|
return;
|
|
513
418
|
}
|
|
514
|
-
|
|
515
419
|
if (!stateMessage.fields.redelivered) return;
|
|
516
|
-
|
|
517
420
|
this._debug(`resume from ${this.status}`);
|
|
518
|
-
|
|
519
421
|
return this.broker.publish('run', stateMessage.fields.routingKey, (0, _messageHelper.cloneContent)(stateMessage.content), stateMessage.properties);
|
|
520
422
|
};
|
|
521
|
-
|
|
522
423
|
proto._onExecutionMessage = function onExecutionMessage(routingKey, message) {
|
|
523
424
|
const {
|
|
524
425
|
content,
|
|
@@ -526,41 +427,34 @@ proto._onExecutionMessage = function onExecutionMessage(routingKey, message) {
|
|
|
526
427
|
} = message;
|
|
527
428
|
const messageType = properties.type;
|
|
528
429
|
message.ack();
|
|
529
|
-
|
|
530
430
|
switch (messageType) {
|
|
531
431
|
case 'stopped':
|
|
532
432
|
{
|
|
533
433
|
return this._onStop();
|
|
534
434
|
}
|
|
535
|
-
|
|
536
435
|
case 'error':
|
|
537
436
|
{
|
|
538
437
|
this.broker.publish('run', 'run.error', content);
|
|
539
438
|
this.broker.publish('run', 'run.discarded', content);
|
|
540
439
|
break;
|
|
541
440
|
}
|
|
542
|
-
|
|
543
441
|
default:
|
|
544
442
|
{
|
|
545
443
|
this.broker.publish('run', 'run.end', content);
|
|
546
444
|
}
|
|
547
445
|
}
|
|
548
|
-
|
|
549
446
|
const executeMessage = this[kExecuteMessage];
|
|
550
447
|
this[kExecuteMessage] = null;
|
|
551
448
|
executeMessage.ack();
|
|
552
449
|
};
|
|
553
|
-
|
|
554
450
|
proto._onApiMessage = function onApiMessage(routingKey, message) {
|
|
555
451
|
if (message.properties.type === 'stop') {
|
|
556
452
|
const execution = this.execution;
|
|
557
|
-
|
|
558
453
|
if (!execution || execution.completed) {
|
|
559
454
|
this._onStop();
|
|
560
455
|
}
|
|
561
456
|
}
|
|
562
457
|
};
|
|
563
|
-
|
|
564
458
|
proto._publishEvent = function publishEvent(action, content, msgOpts) {
|
|
565
459
|
const execution = this.execution;
|
|
566
460
|
this.broker.publish('event', `definition.${action}`, execution ? execution._createMessage(content) : (0, _messageHelper.cloneContent)(content), {
|
|
@@ -568,37 +462,27 @@ proto._publishEvent = function publishEvent(action, content, msgOpts) {
|
|
|
568
462
|
...msgOpts
|
|
569
463
|
});
|
|
570
464
|
};
|
|
571
|
-
|
|
572
465
|
proto._onStop = function onStop() {
|
|
573
466
|
this[kStopped] = true;
|
|
574
|
-
|
|
575
467
|
this._deactivateRunConsumers();
|
|
576
|
-
|
|
577
468
|
return this._publishEvent('stop', this._createMessage());
|
|
578
469
|
};
|
|
579
|
-
|
|
580
470
|
proto._onBrokerReturnFn = function onBrokerReturn(message) {
|
|
581
471
|
if (message.properties.type === 'error') {
|
|
582
472
|
this._deactivateRunConsumers();
|
|
583
|
-
|
|
584
473
|
const err = (0, _Errors.makeErrorFromMessage)(message);
|
|
585
474
|
throw err;
|
|
586
475
|
}
|
|
587
476
|
};
|
|
588
|
-
|
|
589
477
|
proto._reset = function reset() {
|
|
590
478
|
this[kExec].executionId = undefined;
|
|
591
|
-
|
|
592
479
|
this._deactivateRunConsumers();
|
|
593
|
-
|
|
594
480
|
this.broker.purgeQueue('run-q');
|
|
595
481
|
this.broker.purgeQueue('execution-q');
|
|
596
482
|
};
|
|
597
|
-
|
|
598
483
|
proto._debug = function debug(msg) {
|
|
599
484
|
this.logger.debug(`<${this.id}> ${msg}`);
|
|
600
485
|
};
|
|
601
|
-
|
|
602
486
|
function addConsumerCallbacks(definition, callback) {
|
|
603
487
|
const broker = definition.broker;
|
|
604
488
|
clearConsumers();
|
|
@@ -611,20 +495,15 @@ function addConsumerCallbacks(definition, callback) {
|
|
|
611
495
|
broker.subscribeOnce('event', 'definition.error', cbError, {
|
|
612
496
|
consumerTag: '_definition-callback-error'
|
|
613
497
|
});
|
|
614
|
-
|
|
615
498
|
function cbLeave(_, message) {
|
|
616
499
|
clearConsumers();
|
|
617
500
|
return callback(null, definition.getApi(message));
|
|
618
501
|
}
|
|
619
|
-
|
|
620
502
|
function cbError(_, message) {
|
|
621
503
|
clearConsumers();
|
|
622
|
-
|
|
623
504
|
definition._reset();
|
|
624
|
-
|
|
625
505
|
return callback((0, _Errors.makeErrorFromMessage)(message));
|
|
626
506
|
}
|
|
627
|
-
|
|
628
507
|
function clearConsumers() {
|
|
629
508
|
broker.cancel('_definition-callback-stop');
|
|
630
509
|
broker.cancel('_definition-callback-leave');
|