bpmn-elements 13.1.2 → 14.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/dist/Context.js +36 -2
- package/dist/activity/Activity.js +32 -15
- package/dist/definition/DefinitionExecution.js +1 -1
- package/dist/error/Errors.js +6 -1
- package/dist/eventDefinitions/TimerEventDefinition.js +18 -31
- package/dist/getPropertyValue.js +1 -2
- package/dist/index.js +13 -5
- package/package.json +16 -14
- package/src/Api.js +18 -20
- package/src/Context.js +49 -7
- package/src/Environment.js +10 -20
- package/src/EventBroker.js +21 -27
- package/src/MessageFormatter.js +23 -19
- package/src/Tracker.js +4 -4
- package/src/activity/Activity.js +174 -121
- package/src/activity/ActivityExecution.js +38 -29
- package/src/activity/Dummy.js +3 -3
- package/src/activity/Escalation.js +4 -4
- package/src/activity/ExecutionScope.js +4 -4
- package/src/activity/Message.js +5 -5
- package/src/activity/Signal.js +5 -5
- package/src/definition/Definition.js +44 -36
- package/src/definition/DefinitionExecution.js +97 -66
- package/src/error/BpmnError.js +3 -3
- package/src/error/Errors.js +27 -15
- package/src/eventDefinitions/CancelEventDefinition.js +16 -11
- package/src/eventDefinitions/CompensateEventDefinition.js +28 -23
- package/src/eventDefinitions/ConditionalEventDefinition.js +42 -23
- package/src/eventDefinitions/ErrorEventDefinition.js +47 -34
- package/src/eventDefinitions/EscalationEventDefinition.js +21 -20
- package/src/eventDefinitions/EventDefinitionExecution.js +6 -6
- package/src/eventDefinitions/LinkEventDefinition.js +28 -22
- package/src/eventDefinitions/MessageEventDefinition.js +47 -36
- package/src/eventDefinitions/SignalEventDefinition.js +42 -31
- package/src/eventDefinitions/TerminateEventDefinition.js +4 -4
- package/src/eventDefinitions/TimerEventDefinition.js +56 -57
- package/src/events/BoundaryEvent.js +81 -46
- package/src/events/EndEvent.js +2 -2
- package/src/events/IntermediateCatchEvent.js +8 -4
- package/src/events/IntermediateThrowEvent.js +2 -2
- package/src/events/StartEvent.js +29 -18
- package/src/flows/Association.js +11 -11
- package/src/flows/MessageFlow.js +16 -14
- package/src/flows/SequenceFlow.js +22 -20
- package/src/gateways/EventBasedGateway.js +7 -6
- package/src/gateways/ExclusiveGateway.js +4 -4
- package/src/gateways/InclusiveGateway.js +3 -3
- package/src/gateways/ParallelGateway.js +4 -4
- package/src/getPropertyValue.js +3 -6
- package/src/index.js +3 -3
- package/src/io/BpmnIO.js +5 -6
- package/src/io/EnvironmentDataObject.js +2 -3
- package/src/io/EnvironmentDataStore.js +2 -2
- package/src/io/EnvironmentDataStoreReference.js +2 -2
- package/src/io/InputOutputSpecification.js +60 -54
- package/src/io/Properties.js +45 -33
- package/src/messageHelper.js +16 -23
- package/src/process/Lane.js +3 -3
- package/src/process/Process.js +40 -34
- package/src/process/ProcessExecution.js +122 -78
- package/src/tasks/CallActivity.js +109 -57
- package/src/tasks/LoopCharacteristics.js +30 -18
- package/src/tasks/ReceiveTask.js +59 -38
- package/src/tasks/ScriptTask.js +17 -8
- package/src/tasks/ServiceTask.js +16 -9
- package/src/tasks/SignalTask.js +47 -28
- package/src/tasks/StandardLoopCharacteristics.js +3 -3
- package/src/tasks/SubProcess.js +9 -8
- package/src/tasks/Task.js +4 -3
- package/src/tasks/Transaction.js +1 -1
- package/types/index.d.ts +6 -6
- package/types/types.d.ts +39 -35
- package/CHANGELOG.md +0 -459
- package/src/ExtensionsMapper.js +0 -42
- package/src/iso-duration.js +0 -91
package/src/activity/Activity.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import ActivityExecution from './ActivityExecution.js';
|
|
2
|
-
import {getUniqueId} from '../shared.js';
|
|
3
|
-
import {ActivityApi} from '../Api.js';
|
|
4
|
-
import {ActivityBroker} from '../EventBroker.js';
|
|
5
|
-
import {Formatter} from '../MessageFormatter.js';
|
|
6
|
-
import {cloneContent, cloneParent, cloneMessage} from '../messageHelper.js';
|
|
7
|
-
import {makeErrorFromMessage, ActivityError} from '../error/Errors.js';
|
|
2
|
+
import { getUniqueId } from '../shared.js';
|
|
3
|
+
import { ActivityApi } from '../Api.js';
|
|
4
|
+
import { ActivityBroker } from '../EventBroker.js';
|
|
5
|
+
import { Formatter } from '../MessageFormatter.js';
|
|
6
|
+
import { cloneContent, cloneParent, cloneMessage } from '../messageHelper.js';
|
|
7
|
+
import { makeErrorFromMessage, ActivityError } from '../error/Errors.js';
|
|
8
8
|
|
|
9
9
|
const kActivityDef = Symbol.for('activityDefinition');
|
|
10
10
|
const kConsuming = Symbol.for('consuming');
|
|
11
|
+
const kConsumingRunQ = Symbol.for('run queue consumer');
|
|
11
12
|
const kCounters = Symbol.for('counters');
|
|
12
13
|
const kEventDefinitions = Symbol.for('eventDefinitions');
|
|
13
14
|
const kExec = Symbol.for('exec');
|
|
@@ -23,14 +24,14 @@ const kActivated = Symbol.for('activated');
|
|
|
23
24
|
export default Activity;
|
|
24
25
|
|
|
25
26
|
function Activity(Behaviour, activityDef, context) {
|
|
26
|
-
const {id, type = 'activity', name, behaviour = {}} = activityDef;
|
|
27
|
-
const {attachedTo: attachedToRef, eventDefinitions} = behaviour;
|
|
27
|
+
const { id, type = 'activity', name, behaviour = {} } = activityDef;
|
|
28
|
+
const { attachedTo: attachedToRef, eventDefinitions } = behaviour;
|
|
28
29
|
|
|
29
30
|
this[kActivityDef] = activityDef;
|
|
30
31
|
this.id = id;
|
|
31
32
|
this.type = type;
|
|
32
33
|
this.name = name;
|
|
33
|
-
this.behaviour = {...behaviour, eventDefinitions};
|
|
34
|
+
this.behaviour = { ...behaviour, eventDefinitions };
|
|
34
35
|
this.Behaviour = Behaviour;
|
|
35
36
|
this.parent = activityDef.parent ? cloneParent(activityDef.parent) : {};
|
|
36
37
|
this.logger = context.environment.Logger(type.toLowerCase());
|
|
@@ -48,7 +49,7 @@ function Activity(Behaviour, activityDef, context) {
|
|
|
48
49
|
attachedToActivity = context.getActivityById(attachedToRef.id);
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
const {broker, on, once, waitFor, emitFatal} = ActivityBroker(this);
|
|
52
|
+
const { broker, on, once, waitFor, emitFatal } = ActivityBroker(this);
|
|
52
53
|
|
|
53
54
|
this.broker = broker;
|
|
54
55
|
this.on = on;
|
|
@@ -67,14 +68,14 @@ function Activity(Behaviour, activityDef, context) {
|
|
|
67
68
|
inboundTriggers = inboundSequenceFlows.slice();
|
|
68
69
|
}
|
|
69
70
|
const outboundSequenceFlows = context.getOutboundSequenceFlows(id);
|
|
70
|
-
const flows = this[kFlows] = {
|
|
71
|
+
const flows = (this[kFlows] = {
|
|
71
72
|
inboundSequenceFlows,
|
|
72
73
|
inboundAssociations,
|
|
73
74
|
inboundJoinFlows: [],
|
|
74
75
|
inboundTriggers,
|
|
75
76
|
outboundSequenceFlows,
|
|
76
77
|
outboundEvaluator: new OutboundEvaluator(this, outboundSequenceFlows),
|
|
77
|
-
};
|
|
78
|
+
});
|
|
78
79
|
|
|
79
80
|
const isParallelJoin = activityDef.isParallelGateway && flows.inboundSequenceFlows.length > 1;
|
|
80
81
|
this[kFlags] = {
|
|
@@ -100,12 +101,14 @@ function Activity(Behaviour, activityDef, context) {
|
|
|
100
101
|
|
|
101
102
|
this[kEventDefinitions] = eventDefinitions && eventDefinitions.map((ed) => new ed.Behaviour(this, ed, this.context));
|
|
102
103
|
this[kExtensions] = context.loadExtensions(this);
|
|
104
|
+
this[kConsuming] = false;
|
|
105
|
+
this[kConsumingRunQ] = undefined;
|
|
103
106
|
}
|
|
104
107
|
|
|
105
108
|
Object.defineProperties(Activity.prototype, {
|
|
106
109
|
counters: {
|
|
107
110
|
get() {
|
|
108
|
-
return {...this[kCounters]};
|
|
111
|
+
return { ...this[kCounters] };
|
|
109
112
|
},
|
|
110
113
|
},
|
|
111
114
|
execution: {
|
|
@@ -126,7 +129,7 @@ Object.defineProperties(Activity.prototype, {
|
|
|
126
129
|
bpmnIo: {
|
|
127
130
|
get() {
|
|
128
131
|
const extensions = this[kExtensions];
|
|
129
|
-
return extensions && extensions.extensions.find(e => e.type === 'bpmnio');
|
|
132
|
+
return extensions && extensions.extensions.find((e) => e.type === 'bpmnio');
|
|
130
133
|
},
|
|
131
134
|
},
|
|
132
135
|
formatter: {
|
|
@@ -135,11 +138,14 @@ Object.defineProperties(Activity.prototype, {
|
|
|
135
138
|
if (formatter) return formatter;
|
|
136
139
|
|
|
137
140
|
const broker = this.broker;
|
|
138
|
-
formatter = this[kFormatter] = new Formatter(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
formatter = this[kFormatter] = new Formatter(
|
|
142
|
+
{
|
|
143
|
+
id: this.id,
|
|
144
|
+
broker,
|
|
145
|
+
logger: this.logger,
|
|
146
|
+
},
|
|
147
|
+
broker.getQueue('format-run-q'),
|
|
148
|
+
);
|
|
143
149
|
return formatter;
|
|
144
150
|
},
|
|
145
151
|
},
|
|
@@ -206,12 +212,13 @@ Object.defineProperties(Activity.prototype, {
|
|
|
206
212
|
return this.getActivityById(attachedToId);
|
|
207
213
|
},
|
|
208
214
|
},
|
|
209
|
-
lane: {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
+
lane: {
|
|
216
|
+
get() {
|
|
217
|
+
const laneId = this[kFlags].lane;
|
|
218
|
+
if (!laneId) return undefined;
|
|
219
|
+
const parent = this.parentElement;
|
|
220
|
+
return parent.getLaneById && parent.getLaneById(laneId);
|
|
221
|
+
},
|
|
215
222
|
},
|
|
216
223
|
eventDefinitions: {
|
|
217
224
|
get() {
|
|
@@ -226,6 +233,7 @@ Object.defineProperties(Activity.prototype, {
|
|
|
226
233
|
});
|
|
227
234
|
|
|
228
235
|
Activity.prototype.activate = function activate() {
|
|
236
|
+
if (this[kActivated]) return;
|
|
229
237
|
this[kActivated] = true;
|
|
230
238
|
this.addInboundListeners();
|
|
231
239
|
return this._consumeInbound();
|
|
@@ -242,9 +250,9 @@ Activity.prototype.deactivate = function deactivate() {
|
|
|
242
250
|
Activity.prototype.init = function init(initContent) {
|
|
243
251
|
const id = this.id;
|
|
244
252
|
const exec = this[kExec];
|
|
245
|
-
const executionId = exec.initExecutionId = exec.initExecutionId || getUniqueId(id);
|
|
253
|
+
const executionId = (exec.initExecutionId = exec.initExecutionId || getUniqueId(id));
|
|
246
254
|
this.logger.debug(`<${id}> initialized with executionId <${executionId}>`);
|
|
247
|
-
this._publishEvent('init', this._createMessage({...initContent, executionId}));
|
|
255
|
+
this._publishEvent('init', this._createMessage({ ...initContent, executionId }));
|
|
248
256
|
};
|
|
249
257
|
|
|
250
258
|
Activity.prototype.run = function run(runContent) {
|
|
@@ -252,17 +260,18 @@ Activity.prototype.run = function run(runContent) {
|
|
|
252
260
|
if (this.isRunning) throw new Error(`activity <${id}> is already running`);
|
|
253
261
|
|
|
254
262
|
const exec = this[kExec];
|
|
255
|
-
const executionId = exec.executionId = exec.initExecutionId || getUniqueId(id);
|
|
263
|
+
const executionId = (exec.executionId = exec.initExecutionId || getUniqueId(id));
|
|
256
264
|
exec.initExecutionId = null;
|
|
257
265
|
|
|
258
266
|
this._consumeApi();
|
|
259
267
|
|
|
260
|
-
const content = this._createMessage({...runContent, executionId});
|
|
268
|
+
const content = this._createMessage({ ...runContent, executionId });
|
|
261
269
|
const broker = this.broker;
|
|
262
270
|
|
|
263
271
|
broker.publish('run', 'run.enter', content);
|
|
264
272
|
broker.publish('run', 'run.start', cloneContent(content));
|
|
265
273
|
|
|
274
|
+
this[kConsuming] = true;
|
|
266
275
|
this._consumeRunQ();
|
|
267
276
|
};
|
|
268
277
|
|
|
@@ -275,7 +284,7 @@ Activity.prototype.getState = function getState() {
|
|
|
275
284
|
return {
|
|
276
285
|
id: this.id,
|
|
277
286
|
type: this.type,
|
|
278
|
-
...(status && {status}),
|
|
287
|
+
...(status && { status }),
|
|
279
288
|
executionId: exec.executionId,
|
|
280
289
|
stopped: this.stopped,
|
|
281
290
|
counters: this.counters,
|
|
@@ -293,7 +302,7 @@ Activity.prototype.recover = function recover(state) {
|
|
|
293
302
|
const exec = this[kExec];
|
|
294
303
|
exec.executionId = state.executionId;
|
|
295
304
|
|
|
296
|
-
this[kCounters] = {...this[kCounters], ...state.counters};
|
|
305
|
+
this[kCounters] = { ...this[kCounters], ...state.counters };
|
|
297
306
|
|
|
298
307
|
if (state.execution) {
|
|
299
308
|
exec.execution = new ActivityExecution(this, this.context).recover(state.execution);
|
|
@@ -315,7 +324,9 @@ Activity.prototype.resume = function resume() {
|
|
|
315
324
|
this._consumeApi();
|
|
316
325
|
|
|
317
326
|
const content = this._createMessage();
|
|
318
|
-
this.broker.publish('run', 'run.resume', content, {persistent: false});
|
|
327
|
+
this.broker.publish('run', 'run.resume', content, { persistent: false });
|
|
328
|
+
|
|
329
|
+
this[kConsuming] = true;
|
|
319
330
|
this._consumeRunQ();
|
|
320
331
|
};
|
|
321
332
|
|
|
@@ -328,6 +339,7 @@ Activity.prototype.discard = function discard(discardContent) {
|
|
|
328
339
|
const broker = this.broker;
|
|
329
340
|
broker.getQueue('run-q').purge();
|
|
330
341
|
broker.publish('run', 'run.discard', cloneContent(this[kStateMessage].content));
|
|
342
|
+
this[kConsuming] = true;
|
|
331
343
|
this._consumeRunQ();
|
|
332
344
|
};
|
|
333
345
|
|
|
@@ -335,9 +347,11 @@ Activity.prototype.addInboundListeners = function addInboundListeners() {
|
|
|
335
347
|
const onInboundEvent = this._onInboundEvent.bind(this);
|
|
336
348
|
const triggerConsumerTag = `_inbound-${this.id}`;
|
|
337
349
|
for (const trigger of this[kFlows].inboundTriggers) {
|
|
338
|
-
if (trigger.isSequenceFlow)
|
|
339
|
-
|
|
340
|
-
else
|
|
350
|
+
if (trigger.isSequenceFlow)
|
|
351
|
+
trigger.broker.subscribeTmp('event', 'flow.#', onInboundEvent, { noAck: true, consumerTag: triggerConsumerTag });
|
|
352
|
+
else if (this.isForCompensation)
|
|
353
|
+
trigger.broker.subscribeTmp('event', 'association.#', onInboundEvent, { noAck: true, consumerTag: triggerConsumerTag });
|
|
354
|
+
else trigger.broker.subscribeTmp('event', 'activity.#', onInboundEvent, { noAck: true, consumerTag: triggerConsumerTag });
|
|
341
355
|
}
|
|
342
356
|
};
|
|
343
357
|
|
|
@@ -365,7 +379,7 @@ Activity.prototype.next = function next() {
|
|
|
365
379
|
};
|
|
366
380
|
|
|
367
381
|
Activity.prototype.shake = function shake() {
|
|
368
|
-
this._shakeOutbound({content: this._createMessage()});
|
|
382
|
+
this._shakeOutbound({ content: this._createMessage() });
|
|
369
383
|
};
|
|
370
384
|
|
|
371
385
|
Activity.prototype.evaluateOutbound = function evaluateOutbound(fromMessage, discardRestAtTake, callback) {
|
|
@@ -384,14 +398,15 @@ Activity.prototype.getActivityById = function getActivityById(elementId) {
|
|
|
384
398
|
|
|
385
399
|
Activity.prototype._runDiscard = function runDiscard(discardContent) {
|
|
386
400
|
const exec = this[kExec];
|
|
387
|
-
const executionId = exec.executionId = exec.initExecutionId || getUniqueId(this.id);
|
|
401
|
+
const executionId = (exec.executionId = exec.initExecutionId || getUniqueId(this.id));
|
|
388
402
|
exec.initExecutionId = null;
|
|
389
403
|
|
|
390
404
|
this._consumeApi();
|
|
391
405
|
|
|
392
|
-
const content = this._createMessage({...discardContent, executionId});
|
|
406
|
+
const content = this._createMessage({ ...discardContent, executionId });
|
|
393
407
|
this.broker.publish('run', 'run.discard', content);
|
|
394
408
|
|
|
409
|
+
this[kConsuming] = true;
|
|
395
410
|
this._consumeRunQ();
|
|
396
411
|
};
|
|
397
412
|
|
|
@@ -403,6 +418,7 @@ Activity.prototype._discardRun = function discardRun() {
|
|
|
403
418
|
if (execution && !execution.completed) return;
|
|
404
419
|
|
|
405
420
|
switch (status) {
|
|
421
|
+
case 'end':
|
|
406
422
|
case 'executing':
|
|
407
423
|
case 'error':
|
|
408
424
|
case 'discarded':
|
|
@@ -411,24 +427,26 @@ Activity.prototype._discardRun = function discardRun() {
|
|
|
411
427
|
|
|
412
428
|
this._deactivateRunConsumers();
|
|
413
429
|
|
|
414
|
-
const
|
|
415
|
-
if (this.extensions) this.extensions.deactivate(cloneMessage(
|
|
430
|
+
const stateMessage = this[kStateMessage];
|
|
431
|
+
if (this.extensions) this.extensions.deactivate(cloneMessage(stateMessage));
|
|
416
432
|
const broker = this.broker;
|
|
417
433
|
broker.getQueue('run-q').purge();
|
|
418
|
-
|
|
434
|
+
|
|
435
|
+
broker.publish('run', 'run.discard', cloneContent(stateMessage.content));
|
|
436
|
+
this[kConsuming] = true;
|
|
419
437
|
this._consumeRunQ();
|
|
420
438
|
};
|
|
421
439
|
|
|
422
440
|
Activity.prototype._shakeOutbound = function shakeOutbound(sourceMessage) {
|
|
423
441
|
const message = cloneMessage(sourceMessage);
|
|
424
442
|
message.content.sequence = message.content.sequence || [];
|
|
425
|
-
message.content.sequence.push({id: this.id, type: this.type});
|
|
443
|
+
message.content.sequence.push({ id: this.id, type: this.type });
|
|
426
444
|
|
|
427
445
|
const broker = this.broker;
|
|
428
|
-
this.broker.publish('api', 'activity.shake.start', message.content, {persistent: false, type: 'shake'});
|
|
446
|
+
this.broker.publish('api', 'activity.shake.start', message.content, { persistent: false, type: 'shake' });
|
|
429
447
|
|
|
430
448
|
if (this[kFlags].isEnd) {
|
|
431
|
-
return broker.publish('event', 'activity.shake.end', message.content, {persistent: false, type: 'shake'});
|
|
449
|
+
return broker.publish('event', 'activity.shake.end', message.content, { persistent: false, type: 'shake' });
|
|
432
450
|
}
|
|
433
451
|
|
|
434
452
|
for (const flow of this[kFlows].outboundSequenceFlows) flow.shake(message);
|
|
@@ -438,12 +456,15 @@ Activity.prototype._consumeInbound = function consumeInbound() {
|
|
|
438
456
|
if (!this[kActivated]) return;
|
|
439
457
|
|
|
440
458
|
if (this.status) return;
|
|
459
|
+
|
|
441
460
|
const inboundQ = this.broker.getQueue('inbound-q');
|
|
461
|
+
const onInbound = this[kMessageHandlers].onInbound;
|
|
462
|
+
|
|
442
463
|
if (this[kFlags].isParallelJoin) {
|
|
443
|
-
return inboundQ.consume(
|
|
464
|
+
return inboundQ.consume(onInbound, { consumerTag: '_run-on-inbound', prefetch: 1000 });
|
|
444
465
|
}
|
|
445
466
|
|
|
446
|
-
return inboundQ.consume(
|
|
467
|
+
return inboundQ.consume(onInbound, { consumerTag: '_run-on-inbound' });
|
|
447
468
|
};
|
|
448
469
|
|
|
449
470
|
Activity.prototype._onInbound = function onInbound(routingKey, message) {
|
|
@@ -467,14 +488,14 @@ Activity.prototype._onInbound = function onInbound(routingKey, message) {
|
|
|
467
488
|
case 'activity.discard': {
|
|
468
489
|
let discardSequence;
|
|
469
490
|
if (content.discardSequence) discardSequence = content.discardSequence.slice();
|
|
470
|
-
return this._runDiscard({inbound, discardSequence});
|
|
491
|
+
return this._runDiscard({ inbound, discardSequence });
|
|
471
492
|
}
|
|
472
493
|
}
|
|
473
494
|
};
|
|
474
495
|
|
|
475
496
|
Activity.prototype._onJoinInbound = function onJoinInbound(routingKey, message) {
|
|
476
|
-
const {content} = message;
|
|
477
|
-
const {inboundSequenceFlows, inboundJoinFlows, inboundTriggers} = this[kFlows];
|
|
497
|
+
const { content } = message;
|
|
498
|
+
const { inboundSequenceFlows, inboundJoinFlows, inboundTriggers } = this[kFlows];
|
|
478
499
|
const idx = inboundJoinFlows.findIndex((msg) => msg.content.id === content.id);
|
|
479
500
|
|
|
480
501
|
inboundJoinFlows.push(message);
|
|
@@ -509,12 +530,12 @@ Activity.prototype._onJoinInbound = function onJoinInbound(routingKey, message)
|
|
|
509
530
|
|
|
510
531
|
this.broker.cancel('_run-on-inbound');
|
|
511
532
|
|
|
512
|
-
if (!taken) return this._runDiscard({inbound, discardSequence});
|
|
513
|
-
return this.run({inbound});
|
|
533
|
+
if (!taken) return this._runDiscard({ inbound, discardSequence });
|
|
534
|
+
return this.run({ inbound });
|
|
514
535
|
};
|
|
515
536
|
|
|
516
537
|
Activity.prototype._onInboundEvent = function onInboundEvent(routingKey, message) {
|
|
517
|
-
const {fields, content, properties} = message;
|
|
538
|
+
const { fields, content, properties } = message;
|
|
518
539
|
const inboundQ = this.broker.getQueue('inbound-q');
|
|
519
540
|
|
|
520
541
|
switch (routingKey) {
|
|
@@ -536,10 +557,15 @@ Activity.prototype._onInboundEvent = function onInboundEvent(routingKey, message
|
|
|
536
557
|
};
|
|
537
558
|
|
|
538
559
|
Activity.prototype._consumeRunQ = function consumeRunQ() {
|
|
539
|
-
|
|
560
|
+
this[kConsumingRunQ] = true;
|
|
561
|
+
this.broker.getQueue('run-q').assertConsumer(this[kMessageHandlers].onRunMessage, { exclusive: true, consumerTag: '_activity-run' });
|
|
562
|
+
};
|
|
540
563
|
|
|
541
|
-
|
|
542
|
-
|
|
564
|
+
Activity.prototype._pauseRunQ = function pauseRunQ() {
|
|
565
|
+
if (!this[kConsumingRunQ]) return;
|
|
566
|
+
|
|
567
|
+
this[kConsumingRunQ] = false;
|
|
568
|
+
this.broker.cancel('_activity-run');
|
|
543
569
|
};
|
|
544
570
|
|
|
545
571
|
Activity.prototype._onRunMessage = function onRunMessage(routingKey, message, messageProperties) {
|
|
@@ -580,7 +606,7 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
|
|
|
580
606
|
if (!isRedelivered) {
|
|
581
607
|
this[kExec].execution = null;
|
|
582
608
|
if (this.extensions) this.extensions.activate(cloneMessage(message));
|
|
583
|
-
this._publishEvent('enter', content, {correlationId});
|
|
609
|
+
this._publishEvent('enter', content, { correlationId });
|
|
584
610
|
}
|
|
585
611
|
break;
|
|
586
612
|
}
|
|
@@ -593,7 +619,7 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
|
|
|
593
619
|
if (this.extensions) this.extensions.activate(cloneMessage(message));
|
|
594
620
|
|
|
595
621
|
if (!isRedelivered) {
|
|
596
|
-
this.broker.publish('run', 'run.discarded', content, {correlationId});
|
|
622
|
+
this.broker.publish('run', 'run.discarded', content, { correlationId });
|
|
597
623
|
this._publishEvent('discard', content);
|
|
598
624
|
}
|
|
599
625
|
break;
|
|
@@ -602,8 +628,8 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
|
|
|
602
628
|
this.logger.debug(`<${id}> start`, isRedelivered ? 'redelivered' : '');
|
|
603
629
|
this.status = 'started';
|
|
604
630
|
if (!isRedelivered) {
|
|
605
|
-
this.broker.publish('run', 'run.execute', content, {correlationId});
|
|
606
|
-
this._publishEvent('start', content, {correlationId});
|
|
631
|
+
this.broker.publish('run', 'run.execute', content, { correlationId });
|
|
632
|
+
this._publishEvent('start', content, { correlationId });
|
|
607
633
|
}
|
|
608
634
|
break;
|
|
609
635
|
}
|
|
@@ -622,7 +648,9 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
|
|
|
622
648
|
const exec = this[kExec];
|
|
623
649
|
if (isRedelivered && this.extensions) this.extensions.activate(cloneMessage(message));
|
|
624
650
|
if (!exec.execution) exec.execution = new ActivityExecution(this, this.context);
|
|
625
|
-
this.broker
|
|
651
|
+
this.broker
|
|
652
|
+
.getQueue('execution-q')
|
|
653
|
+
.assertConsumer(this[kMessageHandlers].onExecutionMessage, { exclusive: true, consumerTag: '_activity-execution' });
|
|
626
654
|
return exec.execution.execute(message);
|
|
627
655
|
}
|
|
628
656
|
case 'run.end': {
|
|
@@ -634,15 +662,19 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
|
|
|
634
662
|
this.status = 'end';
|
|
635
663
|
|
|
636
664
|
return this._doRunLeave(message, false, () => {
|
|
637
|
-
this._publishEvent('end', content, {correlationId});
|
|
665
|
+
this._publishEvent('end', content, { correlationId });
|
|
638
666
|
if (!step) message.ack();
|
|
639
667
|
});
|
|
640
668
|
}
|
|
641
669
|
case 'run.error': {
|
|
642
|
-
this._publishEvent(
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
670
|
+
this._publishEvent(
|
|
671
|
+
'error',
|
|
672
|
+
{
|
|
673
|
+
...content,
|
|
674
|
+
error: isRedelivered ? makeErrorFromMessage(message) : content.error,
|
|
675
|
+
},
|
|
676
|
+
{ correlationId },
|
|
677
|
+
);
|
|
646
678
|
break;
|
|
647
679
|
}
|
|
648
680
|
case 'run.discarded': {
|
|
@@ -676,15 +708,16 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
|
|
|
676
708
|
if (this.extensions) this.extensions.deactivate(cloneMessage(message));
|
|
677
709
|
|
|
678
710
|
if (!isRedelivered) {
|
|
679
|
-
this.broker.publish('run', 'run.next', content, {persistent: false});
|
|
680
|
-
this._publishEvent('leave', content, {correlationId});
|
|
711
|
+
this.broker.publish('run', 'run.next', content, { persistent: false });
|
|
712
|
+
this._publishEvent('leave', content, { correlationId });
|
|
681
713
|
}
|
|
682
714
|
|
|
683
715
|
break;
|
|
684
716
|
}
|
|
685
717
|
case 'run.next':
|
|
686
|
-
|
|
687
|
-
|
|
718
|
+
message.ack();
|
|
719
|
+
this._pauseRunQ();
|
|
720
|
+
return this._consumeInbound();
|
|
688
721
|
}
|
|
689
722
|
|
|
690
723
|
if (!step) message.ack();
|
|
@@ -696,10 +729,10 @@ Activity.prototype._onExecutionMessage = function onExecutionMessage(routingKey,
|
|
|
696
729
|
...executeMessage.content,
|
|
697
730
|
...message.content,
|
|
698
731
|
executionId: executeMessage.content.executionId,
|
|
699
|
-
parent: {...this.parent},
|
|
732
|
+
parent: { ...this.parent },
|
|
700
733
|
});
|
|
701
734
|
|
|
702
|
-
const {correlationId} = message.properties;
|
|
735
|
+
const { correlationId } = message.properties;
|
|
703
736
|
|
|
704
737
|
this._publishEvent(routingKey, content, message.properties);
|
|
705
738
|
const broker = this.broker;
|
|
@@ -709,24 +742,24 @@ Activity.prototype._onExecutionMessage = function onExecutionMessage(routingKey,
|
|
|
709
742
|
return this._doOutbound(message, false, (err, outbound) => {
|
|
710
743
|
message.ack();
|
|
711
744
|
if (err) return this.emitFatal(err, content);
|
|
712
|
-
broker.publish('run', 'run.execute.passthrough', cloneContent(content, {outbound}));
|
|
745
|
+
broker.publish('run', 'run.execute.passthrough', cloneContent(content, { outbound }));
|
|
713
746
|
return this._ackRunExecuteMessage();
|
|
714
747
|
});
|
|
715
748
|
}
|
|
716
749
|
case 'execution.error': {
|
|
717
750
|
this.status = 'error';
|
|
718
|
-
broker.publish('run', 'run.error', content, {correlationId});
|
|
719
|
-
broker.publish('run', 'run.discarded', content, {correlationId});
|
|
751
|
+
broker.publish('run', 'run.error', content, { correlationId });
|
|
752
|
+
broker.publish('run', 'run.discarded', content, { correlationId });
|
|
720
753
|
break;
|
|
721
754
|
}
|
|
722
755
|
case 'execution.cancel':
|
|
723
756
|
case 'execution.discard':
|
|
724
757
|
this.status = 'discarded';
|
|
725
|
-
broker.publish('run', 'run.discarded', content, {correlationId});
|
|
758
|
+
broker.publish('run', 'run.discarded', content, { correlationId });
|
|
726
759
|
break;
|
|
727
760
|
default: {
|
|
728
761
|
this.status = 'executed';
|
|
729
|
-
broker.publish('run', 'run.end', content, {correlationId});
|
|
762
|
+
broker.publish('run', 'run.end', content, { correlationId });
|
|
730
763
|
}
|
|
731
764
|
}
|
|
732
765
|
|
|
@@ -741,21 +774,26 @@ Activity.prototype._ackRunExecuteMessage = function ackRunExecuteMessage() {
|
|
|
741
774
|
};
|
|
742
775
|
|
|
743
776
|
Activity.prototype._doRunLeave = function doRunLeave(message, isDiscarded, onOutbound) {
|
|
744
|
-
const {content, properties} = message;
|
|
777
|
+
const { content, properties } = message;
|
|
745
778
|
const correlationId = properties.correlationId;
|
|
746
779
|
if (content.ignoreOutbound) {
|
|
747
|
-
this.broker.publish('run', 'run.leave', cloneContent(content), {correlationId});
|
|
780
|
+
this.broker.publish('run', 'run.leave', cloneContent(content), { correlationId });
|
|
748
781
|
return onOutbound();
|
|
749
782
|
}
|
|
750
783
|
|
|
751
784
|
return this._doOutbound(cloneMessage(message), isDiscarded, (err, outbound) => {
|
|
752
785
|
if (err) {
|
|
753
|
-
return this._publishEvent('error', {...content, error: err}, {correlationId});
|
|
786
|
+
return this._publishEvent('error', { ...content, error: err }, { correlationId });
|
|
754
787
|
}
|
|
755
788
|
|
|
756
|
-
this.broker.publish(
|
|
757
|
-
|
|
758
|
-
|
|
789
|
+
this.broker.publish(
|
|
790
|
+
'run',
|
|
791
|
+
'run.leave',
|
|
792
|
+
cloneContent(content, {
|
|
793
|
+
...(outbound.length && { outbound }),
|
|
794
|
+
}),
|
|
795
|
+
{ correlationId },
|
|
796
|
+
);
|
|
759
797
|
|
|
760
798
|
onOutbound();
|
|
761
799
|
});
|
|
@@ -774,7 +812,7 @@ Activity.prototype._doOutbound = function doOutbound(fromMessage, isDiscarded, c
|
|
|
774
812
|
|
|
775
813
|
let outboundFlows;
|
|
776
814
|
if (isDiscarded) {
|
|
777
|
-
outboundFlows = outboundSequenceFlows.map((flow) => formatFlowAction(flow, {action: 'discard'}));
|
|
815
|
+
outboundFlows = outboundSequenceFlows.map((flow) => formatFlowAction(flow, { action: 'discard' }));
|
|
778
816
|
} else if (fromContent.outbound && fromContent.outbound.length) {
|
|
779
817
|
outboundFlows = outboundSequenceFlows.map((flow) => formatFlowAction(flow, fromContent.outbound.filter((f) => f.id === flow.id).pop()));
|
|
780
818
|
}
|
|
@@ -793,15 +831,19 @@ Activity.prototype._doOutbound = function doOutbound(fromMessage, isDiscarded, c
|
|
|
793
831
|
|
|
794
832
|
Activity.prototype._doRunOutbound = function doRunOutbound(outboundList, content, discardSequence) {
|
|
795
833
|
for (const outboundFlow of outboundList) {
|
|
796
|
-
const {id: flowId, action, result} = outboundFlow;
|
|
797
|
-
this.broker.publish(
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
834
|
+
const { id: flowId, action, result } = outboundFlow;
|
|
835
|
+
this.broker.publish(
|
|
836
|
+
'run',
|
|
837
|
+
'run.outbound.' + action,
|
|
838
|
+
cloneContent(content, {
|
|
839
|
+
flow: {
|
|
840
|
+
...(result && typeof result === 'object' && result),
|
|
841
|
+
...outboundFlow,
|
|
842
|
+
sequenceId: getUniqueId(`${flowId}_${action}`),
|
|
843
|
+
...(discardSequence && { discardSequence: discardSequence.slice() }),
|
|
844
|
+
},
|
|
845
|
+
}),
|
|
846
|
+
);
|
|
805
847
|
}
|
|
806
848
|
return outboundList;
|
|
807
849
|
};
|
|
@@ -832,11 +874,10 @@ Activity.prototype._onResumeMessage = function onResumeMessage(message) {
|
|
|
832
874
|
};
|
|
833
875
|
|
|
834
876
|
Activity.prototype._publishEvent = function publishEvent(state, content, properties = {}) {
|
|
835
|
-
this.broker.publish('event', `activity.${state}`, cloneContent(content, {state}), {
|
|
877
|
+
this.broker.publish('event', `activity.${state}`, cloneContent(content, { state }), {
|
|
836
878
|
...properties,
|
|
837
879
|
type: state,
|
|
838
880
|
mandatory: state === 'error',
|
|
839
|
-
persistent: 'persistent' in properties ? properties.persistent : state !== 'stop',
|
|
840
881
|
});
|
|
841
882
|
};
|
|
842
883
|
|
|
@@ -847,15 +888,16 @@ Activity.prototype._onStop = function onStop(message) {
|
|
|
847
888
|
|
|
848
889
|
this[kConsuming] = false;
|
|
849
890
|
const broker = this.broker;
|
|
850
|
-
|
|
891
|
+
this._pauseRunQ();
|
|
851
892
|
broker.cancel('_activity-api');
|
|
852
893
|
broker.cancel('_activity-execution');
|
|
853
894
|
broker.cancel('_run-on-inbound');
|
|
854
895
|
broker.cancel('_format-consumer');
|
|
855
896
|
|
|
897
|
+
if (this.extensions) this.extensions.deactivate(cloneMessage(message));
|
|
898
|
+
|
|
856
899
|
if (running) {
|
|
857
|
-
|
|
858
|
-
this._publishEvent('stop', this._createMessage());
|
|
900
|
+
this._publishEvent('stop', this._createMessage(), { persistent: false });
|
|
859
901
|
}
|
|
860
902
|
};
|
|
861
903
|
|
|
@@ -864,7 +906,11 @@ Activity.prototype._consumeApi = function consumeApi() {
|
|
|
864
906
|
if (!executionId) return;
|
|
865
907
|
const broker = this.broker;
|
|
866
908
|
broker.cancel('_activity-api');
|
|
867
|
-
broker.subscribeTmp('api', `activity.*.${executionId}`, this[kMessageHandlers].onApiMessage, {
|
|
909
|
+
broker.subscribeTmp('api', `activity.*.${executionId}`, this[kMessageHandlers].onApiMessage, {
|
|
910
|
+
noAck: true,
|
|
911
|
+
consumerTag: '_activity-api',
|
|
912
|
+
priority: 100,
|
|
913
|
+
});
|
|
868
914
|
};
|
|
869
915
|
|
|
870
916
|
Activity.prototype._onApiMessage = function onApiMessage(routingKey, message) {
|
|
@@ -882,14 +928,16 @@ Activity.prototype._onApiMessage = function onApiMessage(routingKey, message) {
|
|
|
882
928
|
};
|
|
883
929
|
|
|
884
930
|
Activity.prototype._createMessage = function createMessage(override) {
|
|
885
|
-
const name = this.name,
|
|
931
|
+
const name = this.name,
|
|
932
|
+
status = this.status,
|
|
933
|
+
parent = this.parent;
|
|
886
934
|
const result = {
|
|
887
935
|
...override,
|
|
888
936
|
id: this.id,
|
|
889
937
|
type: this.type,
|
|
890
|
-
...(name && {name}),
|
|
891
|
-
...(status && {status}),
|
|
892
|
-
...(parent && {parent: cloneParent(parent)}),
|
|
938
|
+
...(name && { name }),
|
|
939
|
+
...(status && { status }),
|
|
940
|
+
...(parent && { parent: cloneParent(parent) }),
|
|
893
941
|
};
|
|
894
942
|
|
|
895
943
|
for (const [flag, value] of Object.entries(this[kFlags])) {
|
|
@@ -906,7 +954,7 @@ Activity.prototype._getOutboundSequenceFlowById = function getOutboundSequenceFl
|
|
|
906
954
|
Activity.prototype._deactivateRunConsumers = function _deactivateRunConsumers() {
|
|
907
955
|
const broker = this.broker;
|
|
908
956
|
broker.cancel('_activity-api');
|
|
909
|
-
|
|
957
|
+
this._pauseRunQ();
|
|
910
958
|
broker.cancel('_activity-execution');
|
|
911
959
|
this[kConsuming] = false;
|
|
912
960
|
};
|
|
@@ -914,14 +962,14 @@ Activity.prototype._deactivateRunConsumers = function _deactivateRunConsumers()
|
|
|
914
962
|
function OutboundEvaluator(activity, outboundFlows) {
|
|
915
963
|
this.activity = activity;
|
|
916
964
|
this.broker = activity.broker;
|
|
917
|
-
const flows = this.outboundFlows = outboundFlows.slice();
|
|
918
|
-
const defaultFlowIdx = flows.findIndex(({isDefault}) => isDefault);
|
|
965
|
+
const flows = (this.outboundFlows = outboundFlows.slice());
|
|
966
|
+
const defaultFlowIdx = flows.findIndex(({ isDefault }) => isDefault);
|
|
919
967
|
if (defaultFlowIdx > -1) {
|
|
920
968
|
const [defaultFlow] = flows.splice(defaultFlowIdx, 1);
|
|
921
969
|
flows.push(defaultFlow);
|
|
922
970
|
}
|
|
923
971
|
|
|
924
|
-
this.defaultFlowIdx = outboundFlows.findIndex(({isDefault}) => isDefault);
|
|
972
|
+
this.defaultFlowIdx = outboundFlows.findIndex(({ isDefault }) => isDefault);
|
|
925
973
|
this._onEvaluated = this.onEvaluated.bind(this);
|
|
926
974
|
this.evaluateArgs = {};
|
|
927
975
|
}
|
|
@@ -929,7 +977,7 @@ function OutboundEvaluator(activity, outboundFlows) {
|
|
|
929
977
|
OutboundEvaluator.prototype.evaluate = function evaluate(fromMessage, discardRestAtTake, callback) {
|
|
930
978
|
const outboundFlows = this.outboundFlows;
|
|
931
979
|
|
|
932
|
-
const args = this.evaluateArgs = {
|
|
980
|
+
const args = (this.evaluateArgs = {
|
|
933
981
|
fromMessage,
|
|
934
982
|
evaluationId: fromMessage.content.executionId,
|
|
935
983
|
discardRestAtTake,
|
|
@@ -937,11 +985,11 @@ OutboundEvaluator.prototype.evaluate = function evaluate(fromMessage, discardRes
|
|
|
937
985
|
conditionMet: false,
|
|
938
986
|
result: {},
|
|
939
987
|
takenCount: 0,
|
|
940
|
-
};
|
|
988
|
+
});
|
|
941
989
|
|
|
942
990
|
if (!outboundFlows.length) return this.completed();
|
|
943
991
|
|
|
944
|
-
const flows = args.flows = outboundFlows.slice();
|
|
992
|
+
const flows = (args.flows = outboundFlows.slice());
|
|
945
993
|
|
|
946
994
|
this.broker.subscribeTmp('execution', 'evaluate.flow.#', this._onEvaluated, {
|
|
947
995
|
consumerTag: `_flow-evaluation-${args.evaluationId}`,
|
|
@@ -952,7 +1000,7 @@ OutboundEvaluator.prototype.evaluate = function evaluate(fromMessage, discardRes
|
|
|
952
1000
|
|
|
953
1001
|
OutboundEvaluator.prototype.onEvaluated = function onEvaluated(routingKey, message) {
|
|
954
1002
|
const content = message.content;
|
|
955
|
-
const {id: flowId, action, evaluationId} = message.content;
|
|
1003
|
+
const { id: flowId, action, evaluationId } = message.content;
|
|
956
1004
|
const args = this.evaluateArgs;
|
|
957
1005
|
|
|
958
1006
|
if (action === 'take') {
|
|
@@ -971,13 +1019,13 @@ OutboundEvaluator.prototype.onEvaluated = function onEvaluated(routingKey, messa
|
|
|
971
1019
|
|
|
972
1020
|
if (args.discardRestAtTake && args.conditionMet) {
|
|
973
1021
|
do {
|
|
974
|
-
args.result[nextFlow.id] = formatFlowAction(nextFlow, {action: 'discard'});
|
|
1022
|
+
args.result[nextFlow.id] = formatFlowAction(nextFlow, { action: 'discard' });
|
|
975
1023
|
} while ((nextFlow = args.flows.shift()));
|
|
976
1024
|
return this.completed();
|
|
977
1025
|
}
|
|
978
1026
|
|
|
979
1027
|
if (args.conditionMet && nextFlow.isDefault) {
|
|
980
|
-
args.result[nextFlow.id] = formatFlowAction(nextFlow, {action: 'discard'});
|
|
1028
|
+
args.result[nextFlow.id] = formatFlowAction(nextFlow, { action: 'discard' });
|
|
981
1029
|
return this.completed();
|
|
982
1030
|
}
|
|
983
1031
|
|
|
@@ -987,20 +1035,25 @@ OutboundEvaluator.prototype.onEvaluated = function onEvaluated(routingKey, messa
|
|
|
987
1035
|
|
|
988
1036
|
OutboundEvaluator.prototype.evaluateFlow = function evaluateFlow(flow) {
|
|
989
1037
|
const broker = this.broker;
|
|
990
|
-
const {fromMessage, evaluationId} = this.evaluateArgs;
|
|
1038
|
+
const { fromMessage, evaluationId } = this.evaluateArgs;
|
|
991
1039
|
flow.evaluate(cloneMessage(fromMessage), (err, result) => {
|
|
992
1040
|
if (err) return this.completed(err);
|
|
993
1041
|
const action = result ? 'take' : 'discard';
|
|
994
|
-
return broker.publish(
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
1042
|
+
return broker.publish(
|
|
1043
|
+
'execution',
|
|
1044
|
+
'evaluate.flow.' + action,
|
|
1045
|
+
formatFlowAction(flow, {
|
|
1046
|
+
action,
|
|
1047
|
+
result,
|
|
1048
|
+
evaluationId,
|
|
1049
|
+
}),
|
|
1050
|
+
{ persistent: false },
|
|
1051
|
+
);
|
|
999
1052
|
});
|
|
1000
1053
|
};
|
|
1001
1054
|
|
|
1002
1055
|
OutboundEvaluator.prototype.completed = function completed(err) {
|
|
1003
|
-
const {callback, evaluationId, fromMessage, result, takenCount} = this.evaluateArgs;
|
|
1056
|
+
const { callback, evaluationId, fromMessage, result, takenCount } = this.evaluateArgs;
|
|
1004
1057
|
this.broker.cancel(`_flow-evaluation-${evaluationId}`);
|
|
1005
1058
|
|
|
1006
1059
|
if (err) return callback(err);
|
|
@@ -1015,7 +1068,7 @@ OutboundEvaluator.prototype.completed = function completed(err) {
|
|
|
1015
1068
|
for (const flow of Object.values(result)) {
|
|
1016
1069
|
evaluationResult.push({
|
|
1017
1070
|
...flow,
|
|
1018
|
-
...(message !== undefined && {message}),
|
|
1071
|
+
...(message !== undefined && { message }),
|
|
1019
1072
|
});
|
|
1020
1073
|
}
|
|
1021
1074
|
|
|
@@ -1027,6 +1080,6 @@ function formatFlowAction(flow, options) {
|
|
|
1027
1080
|
...options,
|
|
1028
1081
|
id: flow.id,
|
|
1029
1082
|
action: options.action,
|
|
1030
|
-
...(flow.isDefault && {isDefault: true}),
|
|
1083
|
+
...(flow.isDefault && { isDefault: true }),
|
|
1031
1084
|
};
|
|
1032
1085
|
}
|