bpmn-elements 13.1.1 → 13.2.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/definition/DefinitionExecution.js +2 -1
- package/dist/getPropertyValue.js +1 -2
- package/dist/index.js +1 -1
- package/package.json +14 -13
- 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 +141 -109
- 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 +98 -66
- package/src/error/BpmnError.js +3 -3
- package/src/error/Errors.js +19 -14
- 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 +41 -29
- 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 +1 -1
- 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/iso-duration.js +9 -13
- 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 -455
- package/src/ExtensionsMapper.js +0 -42
package/src/activity/Activity.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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');
|
|
@@ -23,14 +23,14 @@ const kActivated = Symbol.for('activated');
|
|
|
23
23
|
export default Activity;
|
|
24
24
|
|
|
25
25
|
function Activity(Behaviour, activityDef, context) {
|
|
26
|
-
const {id, type = 'activity', name, behaviour = {}} = activityDef;
|
|
27
|
-
const {attachedTo: attachedToRef, eventDefinitions} = behaviour;
|
|
26
|
+
const { id, type = 'activity', name, behaviour = {} } = activityDef;
|
|
27
|
+
const { attachedTo: attachedToRef, eventDefinitions } = behaviour;
|
|
28
28
|
|
|
29
29
|
this[kActivityDef] = activityDef;
|
|
30
30
|
this.id = id;
|
|
31
31
|
this.type = type;
|
|
32
32
|
this.name = name;
|
|
33
|
-
this.behaviour = {...behaviour, eventDefinitions};
|
|
33
|
+
this.behaviour = { ...behaviour, eventDefinitions };
|
|
34
34
|
this.Behaviour = Behaviour;
|
|
35
35
|
this.parent = activityDef.parent ? cloneParent(activityDef.parent) : {};
|
|
36
36
|
this.logger = context.environment.Logger(type.toLowerCase());
|
|
@@ -48,7 +48,7 @@ function Activity(Behaviour, activityDef, context) {
|
|
|
48
48
|
attachedToActivity = context.getActivityById(attachedToRef.id);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
const {broker, on, once, waitFor, emitFatal} = ActivityBroker(this);
|
|
51
|
+
const { broker, on, once, waitFor, emitFatal } = ActivityBroker(this);
|
|
52
52
|
|
|
53
53
|
this.broker = broker;
|
|
54
54
|
this.on = on;
|
|
@@ -67,14 +67,14 @@ function Activity(Behaviour, activityDef, context) {
|
|
|
67
67
|
inboundTriggers = inboundSequenceFlows.slice();
|
|
68
68
|
}
|
|
69
69
|
const outboundSequenceFlows = context.getOutboundSequenceFlows(id);
|
|
70
|
-
const flows = this[kFlows] = {
|
|
70
|
+
const flows = (this[kFlows] = {
|
|
71
71
|
inboundSequenceFlows,
|
|
72
72
|
inboundAssociations,
|
|
73
73
|
inboundJoinFlows: [],
|
|
74
74
|
inboundTriggers,
|
|
75
75
|
outboundSequenceFlows,
|
|
76
76
|
outboundEvaluator: new OutboundEvaluator(this, outboundSequenceFlows),
|
|
77
|
-
};
|
|
77
|
+
});
|
|
78
78
|
|
|
79
79
|
const isParallelJoin = activityDef.isParallelGateway && flows.inboundSequenceFlows.length > 1;
|
|
80
80
|
this[kFlags] = {
|
|
@@ -105,7 +105,7 @@ function Activity(Behaviour, activityDef, context) {
|
|
|
105
105
|
Object.defineProperties(Activity.prototype, {
|
|
106
106
|
counters: {
|
|
107
107
|
get() {
|
|
108
|
-
return {...this[kCounters]};
|
|
108
|
+
return { ...this[kCounters] };
|
|
109
109
|
},
|
|
110
110
|
},
|
|
111
111
|
execution: {
|
|
@@ -126,7 +126,7 @@ Object.defineProperties(Activity.prototype, {
|
|
|
126
126
|
bpmnIo: {
|
|
127
127
|
get() {
|
|
128
128
|
const extensions = this[kExtensions];
|
|
129
|
-
return extensions && extensions.extensions.find(e => e.type === 'bpmnio');
|
|
129
|
+
return extensions && extensions.extensions.find((e) => e.type === 'bpmnio');
|
|
130
130
|
},
|
|
131
131
|
},
|
|
132
132
|
formatter: {
|
|
@@ -135,11 +135,14 @@ Object.defineProperties(Activity.prototype, {
|
|
|
135
135
|
if (formatter) return formatter;
|
|
136
136
|
|
|
137
137
|
const broker = this.broker;
|
|
138
|
-
formatter = this[kFormatter] = new Formatter(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
138
|
+
formatter = this[kFormatter] = new Formatter(
|
|
139
|
+
{
|
|
140
|
+
id: this.id,
|
|
141
|
+
broker,
|
|
142
|
+
logger: this.logger,
|
|
143
|
+
},
|
|
144
|
+
broker.getQueue('format-run-q'),
|
|
145
|
+
);
|
|
143
146
|
return formatter;
|
|
144
147
|
},
|
|
145
148
|
},
|
|
@@ -206,12 +209,13 @@ Object.defineProperties(Activity.prototype, {
|
|
|
206
209
|
return this.getActivityById(attachedToId);
|
|
207
210
|
},
|
|
208
211
|
},
|
|
209
|
-
lane: {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
212
|
+
lane: {
|
|
213
|
+
get() {
|
|
214
|
+
const laneId = this[kFlags].lane;
|
|
215
|
+
if (!laneId) return undefined;
|
|
216
|
+
const parent = this.parentElement;
|
|
217
|
+
return parent.getLaneById && parent.getLaneById(laneId);
|
|
218
|
+
},
|
|
215
219
|
},
|
|
216
220
|
eventDefinitions: {
|
|
217
221
|
get() {
|
|
@@ -242,9 +246,9 @@ Activity.prototype.deactivate = function deactivate() {
|
|
|
242
246
|
Activity.prototype.init = function init(initContent) {
|
|
243
247
|
const id = this.id;
|
|
244
248
|
const exec = this[kExec];
|
|
245
|
-
const executionId = exec.initExecutionId = exec.initExecutionId || getUniqueId(id);
|
|
249
|
+
const executionId = (exec.initExecutionId = exec.initExecutionId || getUniqueId(id));
|
|
246
250
|
this.logger.debug(`<${id}> initialized with executionId <${executionId}>`);
|
|
247
|
-
this._publishEvent('init', this._createMessage({...initContent, executionId}));
|
|
251
|
+
this._publishEvent('init', this._createMessage({ ...initContent, executionId }));
|
|
248
252
|
};
|
|
249
253
|
|
|
250
254
|
Activity.prototype.run = function run(runContent) {
|
|
@@ -252,12 +256,12 @@ Activity.prototype.run = function run(runContent) {
|
|
|
252
256
|
if (this.isRunning) throw new Error(`activity <${id}> is already running`);
|
|
253
257
|
|
|
254
258
|
const exec = this[kExec];
|
|
255
|
-
const executionId = exec.executionId = exec.initExecutionId || getUniqueId(id);
|
|
259
|
+
const executionId = (exec.executionId = exec.initExecutionId || getUniqueId(id));
|
|
256
260
|
exec.initExecutionId = null;
|
|
257
261
|
|
|
258
262
|
this._consumeApi();
|
|
259
263
|
|
|
260
|
-
const content = this._createMessage({...runContent, executionId});
|
|
264
|
+
const content = this._createMessage({ ...runContent, executionId });
|
|
261
265
|
const broker = this.broker;
|
|
262
266
|
|
|
263
267
|
broker.publish('run', 'run.enter', content);
|
|
@@ -275,7 +279,7 @@ Activity.prototype.getState = function getState() {
|
|
|
275
279
|
return {
|
|
276
280
|
id: this.id,
|
|
277
281
|
type: this.type,
|
|
278
|
-
...(status && {status}),
|
|
282
|
+
...(status && { status }),
|
|
279
283
|
executionId: exec.executionId,
|
|
280
284
|
stopped: this.stopped,
|
|
281
285
|
counters: this.counters,
|
|
@@ -293,7 +297,7 @@ Activity.prototype.recover = function recover(state) {
|
|
|
293
297
|
const exec = this[kExec];
|
|
294
298
|
exec.executionId = state.executionId;
|
|
295
299
|
|
|
296
|
-
this[kCounters] = {...this[kCounters], ...state.counters};
|
|
300
|
+
this[kCounters] = { ...this[kCounters], ...state.counters };
|
|
297
301
|
|
|
298
302
|
if (state.execution) {
|
|
299
303
|
exec.execution = new ActivityExecution(this, this.context).recover(state.execution);
|
|
@@ -315,7 +319,7 @@ Activity.prototype.resume = function resume() {
|
|
|
315
319
|
this._consumeApi();
|
|
316
320
|
|
|
317
321
|
const content = this._createMessage();
|
|
318
|
-
this.broker.publish('run', 'run.resume', content, {persistent: false});
|
|
322
|
+
this.broker.publish('run', 'run.resume', content, { persistent: false });
|
|
319
323
|
this._consumeRunQ();
|
|
320
324
|
};
|
|
321
325
|
|
|
@@ -335,9 +339,11 @@ Activity.prototype.addInboundListeners = function addInboundListeners() {
|
|
|
335
339
|
const onInboundEvent = this._onInboundEvent.bind(this);
|
|
336
340
|
const triggerConsumerTag = `_inbound-${this.id}`;
|
|
337
341
|
for (const trigger of this[kFlows].inboundTriggers) {
|
|
338
|
-
if (trigger.isSequenceFlow)
|
|
339
|
-
|
|
340
|
-
else
|
|
342
|
+
if (trigger.isSequenceFlow)
|
|
343
|
+
trigger.broker.subscribeTmp('event', 'flow.#', onInboundEvent, { noAck: true, consumerTag: triggerConsumerTag });
|
|
344
|
+
else if (this.isForCompensation)
|
|
345
|
+
trigger.broker.subscribeTmp('event', 'association.#', onInboundEvent, { noAck: true, consumerTag: triggerConsumerTag });
|
|
346
|
+
else trigger.broker.subscribeTmp('event', 'activity.#', onInboundEvent, { noAck: true, consumerTag: triggerConsumerTag });
|
|
341
347
|
}
|
|
342
348
|
};
|
|
343
349
|
|
|
@@ -365,7 +371,7 @@ Activity.prototype.next = function next() {
|
|
|
365
371
|
};
|
|
366
372
|
|
|
367
373
|
Activity.prototype.shake = function shake() {
|
|
368
|
-
this._shakeOutbound({content: this._createMessage()});
|
|
374
|
+
this._shakeOutbound({ content: this._createMessage() });
|
|
369
375
|
};
|
|
370
376
|
|
|
371
377
|
Activity.prototype.evaluateOutbound = function evaluateOutbound(fromMessage, discardRestAtTake, callback) {
|
|
@@ -384,12 +390,12 @@ Activity.prototype.getActivityById = function getActivityById(elementId) {
|
|
|
384
390
|
|
|
385
391
|
Activity.prototype._runDiscard = function runDiscard(discardContent) {
|
|
386
392
|
const exec = this[kExec];
|
|
387
|
-
const executionId = exec.executionId = exec.initExecutionId || getUniqueId(this.id);
|
|
393
|
+
const executionId = (exec.executionId = exec.initExecutionId || getUniqueId(this.id));
|
|
388
394
|
exec.initExecutionId = null;
|
|
389
395
|
|
|
390
396
|
this._consumeApi();
|
|
391
397
|
|
|
392
|
-
const content = this._createMessage({...discardContent, executionId});
|
|
398
|
+
const content = this._createMessage({ ...discardContent, executionId });
|
|
393
399
|
this.broker.publish('run', 'run.discard', content);
|
|
394
400
|
|
|
395
401
|
this._consumeRunQ();
|
|
@@ -422,13 +428,13 @@ Activity.prototype._discardRun = function discardRun() {
|
|
|
422
428
|
Activity.prototype._shakeOutbound = function shakeOutbound(sourceMessage) {
|
|
423
429
|
const message = cloneMessage(sourceMessage);
|
|
424
430
|
message.content.sequence = message.content.sequence || [];
|
|
425
|
-
message.content.sequence.push({id: this.id, type: this.type});
|
|
431
|
+
message.content.sequence.push({ id: this.id, type: this.type });
|
|
426
432
|
|
|
427
433
|
const broker = this.broker;
|
|
428
|
-
this.broker.publish('api', 'activity.shake.start', message.content, {persistent: false, type: 'shake'});
|
|
434
|
+
this.broker.publish('api', 'activity.shake.start', message.content, { persistent: false, type: 'shake' });
|
|
429
435
|
|
|
430
436
|
if (this[kFlags].isEnd) {
|
|
431
|
-
return broker.publish('event', 'activity.shake.end', message.content, {persistent: false, type: 'shake'});
|
|
437
|
+
return broker.publish('event', 'activity.shake.end', message.content, { persistent: false, type: 'shake' });
|
|
432
438
|
}
|
|
433
439
|
|
|
434
440
|
for (const flow of this[kFlows].outboundSequenceFlows) flow.shake(message);
|
|
@@ -440,10 +446,10 @@ Activity.prototype._consumeInbound = function consumeInbound() {
|
|
|
440
446
|
if (this.status) return;
|
|
441
447
|
const inboundQ = this.broker.getQueue('inbound-q');
|
|
442
448
|
if (this[kFlags].isParallelJoin) {
|
|
443
|
-
return inboundQ.consume(this[kMessageHandlers].onInbound, {consumerTag: '_run-on-inbound', prefetch: 1000});
|
|
449
|
+
return inboundQ.consume(this[kMessageHandlers].onInbound, { consumerTag: '_run-on-inbound', prefetch: 1000 });
|
|
444
450
|
}
|
|
445
451
|
|
|
446
|
-
return inboundQ.consume(this[kMessageHandlers].onInbound, {consumerTag: '_run-on-inbound'});
|
|
452
|
+
return inboundQ.consume(this[kMessageHandlers].onInbound, { consumerTag: '_run-on-inbound' });
|
|
447
453
|
};
|
|
448
454
|
|
|
449
455
|
Activity.prototype._onInbound = function onInbound(routingKey, message) {
|
|
@@ -467,14 +473,14 @@ Activity.prototype._onInbound = function onInbound(routingKey, message) {
|
|
|
467
473
|
case 'activity.discard': {
|
|
468
474
|
let discardSequence;
|
|
469
475
|
if (content.discardSequence) discardSequence = content.discardSequence.slice();
|
|
470
|
-
return this._runDiscard({inbound, discardSequence});
|
|
476
|
+
return this._runDiscard({ inbound, discardSequence });
|
|
471
477
|
}
|
|
472
478
|
}
|
|
473
479
|
};
|
|
474
480
|
|
|
475
481
|
Activity.prototype._onJoinInbound = function onJoinInbound(routingKey, message) {
|
|
476
|
-
const {content} = message;
|
|
477
|
-
const {inboundSequenceFlows, inboundJoinFlows, inboundTriggers} = this[kFlows];
|
|
482
|
+
const { content } = message;
|
|
483
|
+
const { inboundSequenceFlows, inboundJoinFlows, inboundTriggers } = this[kFlows];
|
|
478
484
|
const idx = inboundJoinFlows.findIndex((msg) => msg.content.id === content.id);
|
|
479
485
|
|
|
480
486
|
inboundJoinFlows.push(message);
|
|
@@ -509,12 +515,12 @@ Activity.prototype._onJoinInbound = function onJoinInbound(routingKey, message)
|
|
|
509
515
|
|
|
510
516
|
this.broker.cancel('_run-on-inbound');
|
|
511
517
|
|
|
512
|
-
if (!taken) return this._runDiscard({inbound, discardSequence});
|
|
513
|
-
return this.run({inbound});
|
|
518
|
+
if (!taken) return this._runDiscard({ inbound, discardSequence });
|
|
519
|
+
return this.run({ inbound });
|
|
514
520
|
};
|
|
515
521
|
|
|
516
522
|
Activity.prototype._onInboundEvent = function onInboundEvent(routingKey, message) {
|
|
517
|
-
const {fields, content, properties} = message;
|
|
523
|
+
const { fields, content, properties } = message;
|
|
518
524
|
const inboundQ = this.broker.getQueue('inbound-q');
|
|
519
525
|
|
|
520
526
|
switch (routingKey) {
|
|
@@ -539,7 +545,7 @@ Activity.prototype._consumeRunQ = function consumeRunQ() {
|
|
|
539
545
|
if (this[kConsuming]) return;
|
|
540
546
|
|
|
541
547
|
this[kConsuming] = true;
|
|
542
|
-
this.broker.getQueue('run-q').assertConsumer(this[kMessageHandlers].onRunMessage, {exclusive: true, consumerTag: '_activity-run'});
|
|
548
|
+
this.broker.getQueue('run-q').assertConsumer(this[kMessageHandlers].onRunMessage, { exclusive: true, consumerTag: '_activity-run' });
|
|
543
549
|
};
|
|
544
550
|
|
|
545
551
|
Activity.prototype._onRunMessage = function onRunMessage(routingKey, message, messageProperties) {
|
|
@@ -580,7 +586,7 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
|
|
|
580
586
|
if (!isRedelivered) {
|
|
581
587
|
this[kExec].execution = null;
|
|
582
588
|
if (this.extensions) this.extensions.activate(cloneMessage(message));
|
|
583
|
-
this._publishEvent('enter', content, {correlationId});
|
|
589
|
+
this._publishEvent('enter', content, { correlationId });
|
|
584
590
|
}
|
|
585
591
|
break;
|
|
586
592
|
}
|
|
@@ -593,7 +599,7 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
|
|
|
593
599
|
if (this.extensions) this.extensions.activate(cloneMessage(message));
|
|
594
600
|
|
|
595
601
|
if (!isRedelivered) {
|
|
596
|
-
this.broker.publish('run', 'run.discarded', content, {correlationId});
|
|
602
|
+
this.broker.publish('run', 'run.discarded', content, { correlationId });
|
|
597
603
|
this._publishEvent('discard', content);
|
|
598
604
|
}
|
|
599
605
|
break;
|
|
@@ -602,8 +608,8 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
|
|
|
602
608
|
this.logger.debug(`<${id}> start`, isRedelivered ? 'redelivered' : '');
|
|
603
609
|
this.status = 'started';
|
|
604
610
|
if (!isRedelivered) {
|
|
605
|
-
this.broker.publish('run', 'run.execute', content, {correlationId});
|
|
606
|
-
this._publishEvent('start', content, {correlationId});
|
|
611
|
+
this.broker.publish('run', 'run.execute', content, { correlationId });
|
|
612
|
+
this._publishEvent('start', content, { correlationId });
|
|
607
613
|
}
|
|
608
614
|
break;
|
|
609
615
|
}
|
|
@@ -622,7 +628,9 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
|
|
|
622
628
|
const exec = this[kExec];
|
|
623
629
|
if (isRedelivered && this.extensions) this.extensions.activate(cloneMessage(message));
|
|
624
630
|
if (!exec.execution) exec.execution = new ActivityExecution(this, this.context);
|
|
625
|
-
this.broker
|
|
631
|
+
this.broker
|
|
632
|
+
.getQueue('execution-q')
|
|
633
|
+
.assertConsumer(this[kMessageHandlers].onExecutionMessage, { exclusive: true, consumerTag: '_activity-execution' });
|
|
626
634
|
return exec.execution.execute(message);
|
|
627
635
|
}
|
|
628
636
|
case 'run.end': {
|
|
@@ -634,15 +642,19 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
|
|
|
634
642
|
this.status = 'end';
|
|
635
643
|
|
|
636
644
|
return this._doRunLeave(message, false, () => {
|
|
637
|
-
this._publishEvent('end', content, {correlationId});
|
|
645
|
+
this._publishEvent('end', content, { correlationId });
|
|
638
646
|
if (!step) message.ack();
|
|
639
647
|
});
|
|
640
648
|
}
|
|
641
649
|
case 'run.error': {
|
|
642
|
-
this._publishEvent(
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
650
|
+
this._publishEvent(
|
|
651
|
+
'error',
|
|
652
|
+
{
|
|
653
|
+
...content,
|
|
654
|
+
error: isRedelivered ? makeErrorFromMessage(message) : content.error,
|
|
655
|
+
},
|
|
656
|
+
{ correlationId },
|
|
657
|
+
);
|
|
646
658
|
break;
|
|
647
659
|
}
|
|
648
660
|
case 'run.discarded': {
|
|
@@ -676,8 +688,8 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
|
|
|
676
688
|
if (this.extensions) this.extensions.deactivate(cloneMessage(message));
|
|
677
689
|
|
|
678
690
|
if (!isRedelivered) {
|
|
679
|
-
this.broker.publish('run', 'run.next', content, {persistent: false});
|
|
680
|
-
this._publishEvent('leave', content, {correlationId});
|
|
691
|
+
this.broker.publish('run', 'run.next', content, { persistent: false });
|
|
692
|
+
this._publishEvent('leave', content, { correlationId });
|
|
681
693
|
}
|
|
682
694
|
|
|
683
695
|
break;
|
|
@@ -696,10 +708,10 @@ Activity.prototype._onExecutionMessage = function onExecutionMessage(routingKey,
|
|
|
696
708
|
...executeMessage.content,
|
|
697
709
|
...message.content,
|
|
698
710
|
executionId: executeMessage.content.executionId,
|
|
699
|
-
parent: {...this.parent},
|
|
711
|
+
parent: { ...this.parent },
|
|
700
712
|
});
|
|
701
713
|
|
|
702
|
-
const {correlationId} = message.properties;
|
|
714
|
+
const { correlationId } = message.properties;
|
|
703
715
|
|
|
704
716
|
this._publishEvent(routingKey, content, message.properties);
|
|
705
717
|
const broker = this.broker;
|
|
@@ -709,24 +721,24 @@ Activity.prototype._onExecutionMessage = function onExecutionMessage(routingKey,
|
|
|
709
721
|
return this._doOutbound(message, false, (err, outbound) => {
|
|
710
722
|
message.ack();
|
|
711
723
|
if (err) return this.emitFatal(err, content);
|
|
712
|
-
broker.publish('run', 'run.execute.passthrough', cloneContent(content, {outbound}));
|
|
724
|
+
broker.publish('run', 'run.execute.passthrough', cloneContent(content, { outbound }));
|
|
713
725
|
return this._ackRunExecuteMessage();
|
|
714
726
|
});
|
|
715
727
|
}
|
|
716
728
|
case 'execution.error': {
|
|
717
729
|
this.status = 'error';
|
|
718
|
-
broker.publish('run', 'run.error', content, {correlationId});
|
|
719
|
-
broker.publish('run', 'run.discarded', content, {correlationId});
|
|
730
|
+
broker.publish('run', 'run.error', content, { correlationId });
|
|
731
|
+
broker.publish('run', 'run.discarded', content, { correlationId });
|
|
720
732
|
break;
|
|
721
733
|
}
|
|
722
734
|
case 'execution.cancel':
|
|
723
735
|
case 'execution.discard':
|
|
724
736
|
this.status = 'discarded';
|
|
725
|
-
broker.publish('run', 'run.discarded', content, {correlationId});
|
|
737
|
+
broker.publish('run', 'run.discarded', content, { correlationId });
|
|
726
738
|
break;
|
|
727
739
|
default: {
|
|
728
740
|
this.status = 'executed';
|
|
729
|
-
broker.publish('run', 'run.end', content, {correlationId});
|
|
741
|
+
broker.publish('run', 'run.end', content, { correlationId });
|
|
730
742
|
}
|
|
731
743
|
}
|
|
732
744
|
|
|
@@ -741,21 +753,26 @@ Activity.prototype._ackRunExecuteMessage = function ackRunExecuteMessage() {
|
|
|
741
753
|
};
|
|
742
754
|
|
|
743
755
|
Activity.prototype._doRunLeave = function doRunLeave(message, isDiscarded, onOutbound) {
|
|
744
|
-
const {content, properties} = message;
|
|
756
|
+
const { content, properties } = message;
|
|
745
757
|
const correlationId = properties.correlationId;
|
|
746
758
|
if (content.ignoreOutbound) {
|
|
747
|
-
this.broker.publish('run', 'run.leave', cloneContent(content), {correlationId});
|
|
759
|
+
this.broker.publish('run', 'run.leave', cloneContent(content), { correlationId });
|
|
748
760
|
return onOutbound();
|
|
749
761
|
}
|
|
750
762
|
|
|
751
763
|
return this._doOutbound(cloneMessage(message), isDiscarded, (err, outbound) => {
|
|
752
764
|
if (err) {
|
|
753
|
-
return this._publishEvent('error', {...content, error: err}, {correlationId});
|
|
765
|
+
return this._publishEvent('error', { ...content, error: err }, { correlationId });
|
|
754
766
|
}
|
|
755
767
|
|
|
756
|
-
this.broker.publish(
|
|
757
|
-
|
|
758
|
-
|
|
768
|
+
this.broker.publish(
|
|
769
|
+
'run',
|
|
770
|
+
'run.leave',
|
|
771
|
+
cloneContent(content, {
|
|
772
|
+
...(outbound.length && { outbound }),
|
|
773
|
+
}),
|
|
774
|
+
{ correlationId },
|
|
775
|
+
);
|
|
759
776
|
|
|
760
777
|
onOutbound();
|
|
761
778
|
});
|
|
@@ -774,7 +791,7 @@ Activity.prototype._doOutbound = function doOutbound(fromMessage, isDiscarded, c
|
|
|
774
791
|
|
|
775
792
|
let outboundFlows;
|
|
776
793
|
if (isDiscarded) {
|
|
777
|
-
outboundFlows = outboundSequenceFlows.map((flow) => formatFlowAction(flow, {action: 'discard'}));
|
|
794
|
+
outboundFlows = outboundSequenceFlows.map((flow) => formatFlowAction(flow, { action: 'discard' }));
|
|
778
795
|
} else if (fromContent.outbound && fromContent.outbound.length) {
|
|
779
796
|
outboundFlows = outboundSequenceFlows.map((flow) => formatFlowAction(flow, fromContent.outbound.filter((f) => f.id === flow.id).pop()));
|
|
780
797
|
}
|
|
@@ -793,15 +810,19 @@ Activity.prototype._doOutbound = function doOutbound(fromMessage, isDiscarded, c
|
|
|
793
810
|
|
|
794
811
|
Activity.prototype._doRunOutbound = function doRunOutbound(outboundList, content, discardSequence) {
|
|
795
812
|
for (const outboundFlow of outboundList) {
|
|
796
|
-
const {id: flowId, action, result} = outboundFlow;
|
|
797
|
-
this.broker.publish(
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
813
|
+
const { id: flowId, action, result } = outboundFlow;
|
|
814
|
+
this.broker.publish(
|
|
815
|
+
'run',
|
|
816
|
+
'run.outbound.' + action,
|
|
817
|
+
cloneContent(content, {
|
|
818
|
+
flow: {
|
|
819
|
+
...(result && typeof result === 'object' && result),
|
|
820
|
+
...outboundFlow,
|
|
821
|
+
sequenceId: getUniqueId(`${flowId}_${action}`),
|
|
822
|
+
...(discardSequence && { discardSequence: discardSequence.slice() }),
|
|
823
|
+
},
|
|
824
|
+
}),
|
|
825
|
+
);
|
|
805
826
|
}
|
|
806
827
|
return outboundList;
|
|
807
828
|
};
|
|
@@ -832,7 +853,7 @@ Activity.prototype._onResumeMessage = function onResumeMessage(message) {
|
|
|
832
853
|
};
|
|
833
854
|
|
|
834
855
|
Activity.prototype._publishEvent = function publishEvent(state, content, properties = {}) {
|
|
835
|
-
this.broker.publish('event', `activity.${state}`, cloneContent(content, {state}), {
|
|
856
|
+
this.broker.publish('event', `activity.${state}`, cloneContent(content, { state }), {
|
|
836
857
|
...properties,
|
|
837
858
|
type: state,
|
|
838
859
|
mandatory: state === 'error',
|
|
@@ -864,7 +885,11 @@ Activity.prototype._consumeApi = function consumeApi() {
|
|
|
864
885
|
if (!executionId) return;
|
|
865
886
|
const broker = this.broker;
|
|
866
887
|
broker.cancel('_activity-api');
|
|
867
|
-
broker.subscribeTmp('api', `activity.*.${executionId}`, this[kMessageHandlers].onApiMessage, {
|
|
888
|
+
broker.subscribeTmp('api', `activity.*.${executionId}`, this[kMessageHandlers].onApiMessage, {
|
|
889
|
+
noAck: true,
|
|
890
|
+
consumerTag: '_activity-api',
|
|
891
|
+
priority: 100,
|
|
892
|
+
});
|
|
868
893
|
};
|
|
869
894
|
|
|
870
895
|
Activity.prototype._onApiMessage = function onApiMessage(routingKey, message) {
|
|
@@ -882,14 +907,16 @@ Activity.prototype._onApiMessage = function onApiMessage(routingKey, message) {
|
|
|
882
907
|
};
|
|
883
908
|
|
|
884
909
|
Activity.prototype._createMessage = function createMessage(override) {
|
|
885
|
-
const name = this.name,
|
|
910
|
+
const name = this.name,
|
|
911
|
+
status = this.status,
|
|
912
|
+
parent = this.parent;
|
|
886
913
|
const result = {
|
|
887
914
|
...override,
|
|
888
915
|
id: this.id,
|
|
889
916
|
type: this.type,
|
|
890
|
-
...(name && {name}),
|
|
891
|
-
...(status && {status}),
|
|
892
|
-
...(parent && {parent: cloneParent(parent)}),
|
|
917
|
+
...(name && { name }),
|
|
918
|
+
...(status && { status }),
|
|
919
|
+
...(parent && { parent: cloneParent(parent) }),
|
|
893
920
|
};
|
|
894
921
|
|
|
895
922
|
for (const [flag, value] of Object.entries(this[kFlags])) {
|
|
@@ -914,14 +941,14 @@ Activity.prototype._deactivateRunConsumers = function _deactivateRunConsumers()
|
|
|
914
941
|
function OutboundEvaluator(activity, outboundFlows) {
|
|
915
942
|
this.activity = activity;
|
|
916
943
|
this.broker = activity.broker;
|
|
917
|
-
const flows = this.outboundFlows = outboundFlows.slice();
|
|
918
|
-
const defaultFlowIdx = flows.findIndex(({isDefault}) => isDefault);
|
|
944
|
+
const flows = (this.outboundFlows = outboundFlows.slice());
|
|
945
|
+
const defaultFlowIdx = flows.findIndex(({ isDefault }) => isDefault);
|
|
919
946
|
if (defaultFlowIdx > -1) {
|
|
920
947
|
const [defaultFlow] = flows.splice(defaultFlowIdx, 1);
|
|
921
948
|
flows.push(defaultFlow);
|
|
922
949
|
}
|
|
923
950
|
|
|
924
|
-
this.defaultFlowIdx = outboundFlows.findIndex(({isDefault}) => isDefault);
|
|
951
|
+
this.defaultFlowIdx = outboundFlows.findIndex(({ isDefault }) => isDefault);
|
|
925
952
|
this._onEvaluated = this.onEvaluated.bind(this);
|
|
926
953
|
this.evaluateArgs = {};
|
|
927
954
|
}
|
|
@@ -929,7 +956,7 @@ function OutboundEvaluator(activity, outboundFlows) {
|
|
|
929
956
|
OutboundEvaluator.prototype.evaluate = function evaluate(fromMessage, discardRestAtTake, callback) {
|
|
930
957
|
const outboundFlows = this.outboundFlows;
|
|
931
958
|
|
|
932
|
-
const args = this.evaluateArgs = {
|
|
959
|
+
const args = (this.evaluateArgs = {
|
|
933
960
|
fromMessage,
|
|
934
961
|
evaluationId: fromMessage.content.executionId,
|
|
935
962
|
discardRestAtTake,
|
|
@@ -937,11 +964,11 @@ OutboundEvaluator.prototype.evaluate = function evaluate(fromMessage, discardRes
|
|
|
937
964
|
conditionMet: false,
|
|
938
965
|
result: {},
|
|
939
966
|
takenCount: 0,
|
|
940
|
-
};
|
|
967
|
+
});
|
|
941
968
|
|
|
942
969
|
if (!outboundFlows.length) return this.completed();
|
|
943
970
|
|
|
944
|
-
const flows = args.flows = outboundFlows.slice();
|
|
971
|
+
const flows = (args.flows = outboundFlows.slice());
|
|
945
972
|
|
|
946
973
|
this.broker.subscribeTmp('execution', 'evaluate.flow.#', this._onEvaluated, {
|
|
947
974
|
consumerTag: `_flow-evaluation-${args.evaluationId}`,
|
|
@@ -952,7 +979,7 @@ OutboundEvaluator.prototype.evaluate = function evaluate(fromMessage, discardRes
|
|
|
952
979
|
|
|
953
980
|
OutboundEvaluator.prototype.onEvaluated = function onEvaluated(routingKey, message) {
|
|
954
981
|
const content = message.content;
|
|
955
|
-
const {id: flowId, action, evaluationId} = message.content;
|
|
982
|
+
const { id: flowId, action, evaluationId } = message.content;
|
|
956
983
|
const args = this.evaluateArgs;
|
|
957
984
|
|
|
958
985
|
if (action === 'take') {
|
|
@@ -971,13 +998,13 @@ OutboundEvaluator.prototype.onEvaluated = function onEvaluated(routingKey, messa
|
|
|
971
998
|
|
|
972
999
|
if (args.discardRestAtTake && args.conditionMet) {
|
|
973
1000
|
do {
|
|
974
|
-
args.result[nextFlow.id] = formatFlowAction(nextFlow, {action: 'discard'});
|
|
1001
|
+
args.result[nextFlow.id] = formatFlowAction(nextFlow, { action: 'discard' });
|
|
975
1002
|
} while ((nextFlow = args.flows.shift()));
|
|
976
1003
|
return this.completed();
|
|
977
1004
|
}
|
|
978
1005
|
|
|
979
1006
|
if (args.conditionMet && nextFlow.isDefault) {
|
|
980
|
-
args.result[nextFlow.id] = formatFlowAction(nextFlow, {action: 'discard'});
|
|
1007
|
+
args.result[nextFlow.id] = formatFlowAction(nextFlow, { action: 'discard' });
|
|
981
1008
|
return this.completed();
|
|
982
1009
|
}
|
|
983
1010
|
|
|
@@ -987,20 +1014,25 @@ OutboundEvaluator.prototype.onEvaluated = function onEvaluated(routingKey, messa
|
|
|
987
1014
|
|
|
988
1015
|
OutboundEvaluator.prototype.evaluateFlow = function evaluateFlow(flow) {
|
|
989
1016
|
const broker = this.broker;
|
|
990
|
-
const {fromMessage, evaluationId} = this.evaluateArgs;
|
|
1017
|
+
const { fromMessage, evaluationId } = this.evaluateArgs;
|
|
991
1018
|
flow.evaluate(cloneMessage(fromMessage), (err, result) => {
|
|
992
1019
|
if (err) return this.completed(err);
|
|
993
1020
|
const action = result ? 'take' : 'discard';
|
|
994
|
-
return broker.publish(
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
1021
|
+
return broker.publish(
|
|
1022
|
+
'execution',
|
|
1023
|
+
'evaluate.flow.' + action,
|
|
1024
|
+
formatFlowAction(flow, {
|
|
1025
|
+
action,
|
|
1026
|
+
result,
|
|
1027
|
+
evaluationId,
|
|
1028
|
+
}),
|
|
1029
|
+
{ persistent: false },
|
|
1030
|
+
);
|
|
999
1031
|
});
|
|
1000
1032
|
};
|
|
1001
1033
|
|
|
1002
1034
|
OutboundEvaluator.prototype.completed = function completed(err) {
|
|
1003
|
-
const {callback, evaluationId, fromMessage, result, takenCount} = this.evaluateArgs;
|
|
1035
|
+
const { callback, evaluationId, fromMessage, result, takenCount } = this.evaluateArgs;
|
|
1004
1036
|
this.broker.cancel(`_flow-evaluation-${evaluationId}`);
|
|
1005
1037
|
|
|
1006
1038
|
if (err) return callback(err);
|
|
@@ -1015,7 +1047,7 @@ OutboundEvaluator.prototype.completed = function completed(err) {
|
|
|
1015
1047
|
for (const flow of Object.values(result)) {
|
|
1016
1048
|
evaluationResult.push({
|
|
1017
1049
|
...flow,
|
|
1018
|
-
...(message !== undefined && {message}),
|
|
1050
|
+
...(message !== undefined && { message }),
|
|
1019
1051
|
});
|
|
1020
1052
|
}
|
|
1021
1053
|
|
|
@@ -1027,6 +1059,6 @@ function formatFlowAction(flow, options) {
|
|
|
1027
1059
|
...options,
|
|
1028
1060
|
id: flow.id,
|
|
1029
1061
|
action: options.action,
|
|
1030
|
-
...(flow.isDefault && {isDefault: true}),
|
|
1062
|
+
...(flow.isDefault && { isDefault: true }),
|
|
1031
1063
|
};
|
|
1032
1064
|
}
|