bpmn-elements 14.1.0 → 15.0.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/README.md +0 -4
- package/dist/Context.js +41 -35
- package/dist/Environment.js +4 -4
- package/dist/Expressions.js +1 -1
- package/dist/MessageFormatter.js +0 -1
- package/dist/Scripts.js +3 -8
- package/dist/Timers.js +5 -9
- package/dist/Tracker.js +15 -19
- package/dist/activity/Activity.js +68 -49
- package/dist/activity/ActivityExecution.js +43 -29
- package/dist/definition/Definition.js +20 -14
- package/dist/definition/DefinitionExecution.js +64 -55
- package/dist/eventDefinitions/EscalationEventDefinition.js +1 -1
- package/dist/eventDefinitions/LinkEventDefinition.js +1 -1
- package/dist/eventDefinitions/MessageEventDefinition.js +1 -1
- package/dist/eventDefinitions/SignalEventDefinition.js +1 -1
- package/dist/eventDefinitions/TimerEventDefinition.js +1 -1
- package/dist/events/BoundaryEvent.js +11 -9
- package/dist/events/EndEvent.js +1 -1
- package/dist/events/IntermediateCatchEvent.js +1 -1
- package/dist/events/IntermediateThrowEvent.js +1 -1
- package/dist/events/StartEvent.js +1 -1
- package/dist/flows/SequenceFlow.js +1 -1
- package/dist/gateways/EventBasedGateway.js +1 -1
- package/dist/gateways/ExclusiveGateway.js +1 -1
- package/dist/gateways/InclusiveGateway.js +1 -1
- package/dist/gateways/ParallelGateway.js +1 -1
- package/dist/index.js +1 -1
- package/dist/io/InputOutputSpecification.js +1 -1
- package/dist/io/Properties.js +1 -1
- package/dist/process/Process.js +20 -19
- package/dist/process/ProcessExecution.js +67 -40
- package/dist/shared.js +0 -8
- package/dist/tasks/CallActivity.js +1 -1
- package/dist/tasks/LoopCharacteristics.js +2 -2
- package/dist/tasks/ReceiveTask.js +1 -1
- package/dist/tasks/ScriptTask.js +3 -3
- package/dist/tasks/ServiceImplementation.js +1 -1
- package/dist/tasks/ServiceTask.js +1 -1
- package/dist/tasks/SignalTask.js +1 -1
- package/dist/tasks/StandardLoopCharacteristics.js +1 -1
- package/dist/tasks/SubProcess.js +30 -33
- package/dist/tasks/Task.js +1 -1
- package/dist/tasks/Transaction.js +1 -1
- package/package.json +4 -4
- package/src/Context.js +51 -35
- package/src/Environment.js +4 -4
- package/src/MessageFormatter.js +0 -3
- package/src/Scripts.js +3 -8
- package/src/Timers.js +5 -9
- package/src/Tracker.js +13 -17
- package/src/activity/Activity.js +57 -42
- package/src/activity/ActivityExecution.js +43 -26
- package/src/definition/Definition.js +19 -13
- package/src/definition/DefinitionExecution.js +64 -54
- package/src/eventDefinitions/TimerEventDefinition.js +1 -1
- package/src/events/BoundaryEvent.js +10 -8
- package/src/process/Process.js +20 -15
- package/src/process/ProcessExecution.js +70 -40
- package/src/shared.js +0 -8
- package/src/tasks/LoopCharacteristics.js +2 -2
- package/src/tasks/ScriptTask.js +2 -2
- package/src/tasks/SubProcess.js +31 -32
- package/types/types.d.ts +1 -1
package/src/activity/Activity.js
CHANGED
|
@@ -71,7 +71,7 @@ function Activity(Behaviour, activityDef, context) {
|
|
|
71
71
|
const flows = (this[kFlows] = {
|
|
72
72
|
inboundSequenceFlows,
|
|
73
73
|
inboundAssociations,
|
|
74
|
-
inboundJoinFlows:
|
|
74
|
+
inboundJoinFlows: new Set(),
|
|
75
75
|
inboundTriggers,
|
|
76
76
|
outboundSequenceFlows,
|
|
77
77
|
outboundEvaluator: new OutboundEvaluator(this, outboundSequenceFlows),
|
|
@@ -90,7 +90,7 @@ function Activity(Behaviour, activityDef, context) {
|
|
|
90
90
|
isThrowing: activityDef.isThrowing,
|
|
91
91
|
lane: activityDef.lane && activityDef.lane.id,
|
|
92
92
|
};
|
|
93
|
-
this[kExec] =
|
|
93
|
+
this[kExec] = new Map();
|
|
94
94
|
|
|
95
95
|
this[kMessageHandlers] = {
|
|
96
96
|
onInbound: isParallelJoin ? this._onJoinInbound.bind(this) : this._onInbound.bind(this),
|
|
@@ -113,12 +113,12 @@ Object.defineProperties(Activity.prototype, {
|
|
|
113
113
|
},
|
|
114
114
|
execution: {
|
|
115
115
|
get() {
|
|
116
|
-
return this[kExec].execution;
|
|
116
|
+
return this[kExec].get('execution');
|
|
117
117
|
},
|
|
118
118
|
},
|
|
119
119
|
executionId: {
|
|
120
120
|
get() {
|
|
121
|
-
return this[kExec].executionId;
|
|
121
|
+
return this[kExec].get('executionId');
|
|
122
122
|
},
|
|
123
123
|
},
|
|
124
124
|
extensions: {
|
|
@@ -250,7 +250,8 @@ Activity.prototype.deactivate = function deactivate() {
|
|
|
250
250
|
Activity.prototype.init = function init(initContent) {
|
|
251
251
|
const id = this.id;
|
|
252
252
|
const exec = this[kExec];
|
|
253
|
-
const executionId =
|
|
253
|
+
const executionId = exec.has('initExecutionId') ? exec.get('initExecutionId') : getUniqueId(id);
|
|
254
|
+
exec.set('initExecutionId', executionId);
|
|
254
255
|
this.logger.debug(`<${id}> initialized with executionId <${executionId}>`);
|
|
255
256
|
this._publishEvent('init', this._createMessage({ ...initContent, executionId }));
|
|
256
257
|
};
|
|
@@ -260,8 +261,9 @@ Activity.prototype.run = function run(runContent) {
|
|
|
260
261
|
if (this.isRunning) throw new Error(`activity <${id}> is already running`);
|
|
261
262
|
|
|
262
263
|
const exec = this[kExec];
|
|
263
|
-
const executionId =
|
|
264
|
-
exec.
|
|
264
|
+
const executionId = exec.get('initExecutionId') || getUniqueId(id);
|
|
265
|
+
exec.set('executionId', executionId);
|
|
266
|
+
exec.delete('initExecutionId');
|
|
265
267
|
|
|
266
268
|
this._consumeApi();
|
|
267
269
|
|
|
@@ -278,6 +280,8 @@ Activity.prototype.run = function run(runContent) {
|
|
|
278
280
|
Activity.prototype.getState = function getState() {
|
|
279
281
|
const status = this.status;
|
|
280
282
|
const exec = this[kExec];
|
|
283
|
+
const execution = exec.get('execution');
|
|
284
|
+
const executionId = exec.get('executionId');
|
|
281
285
|
const brokerState = this.broker.getState(true);
|
|
282
286
|
if (!brokerState && this.environment.settings.disableTrackState) return;
|
|
283
287
|
|
|
@@ -285,11 +289,11 @@ Activity.prototype.getState = function getState() {
|
|
|
285
289
|
id: this.id,
|
|
286
290
|
type: this.type,
|
|
287
291
|
...(status && { status }),
|
|
288
|
-
executionId
|
|
292
|
+
executionId,
|
|
289
293
|
stopped: this.stopped,
|
|
290
294
|
counters: this.counters,
|
|
291
295
|
broker: brokerState,
|
|
292
|
-
execution
|
|
296
|
+
...(execution && { execution: execution.getState() }),
|
|
293
297
|
};
|
|
294
298
|
};
|
|
295
299
|
|
|
@@ -300,12 +304,12 @@ Activity.prototype.recover = function recover(state) {
|
|
|
300
304
|
this.stopped = state.stopped;
|
|
301
305
|
this.status = state.status;
|
|
302
306
|
const exec = this[kExec];
|
|
303
|
-
exec.executionId
|
|
307
|
+
exec.set('executionId', state.executionId);
|
|
304
308
|
|
|
305
309
|
this[kCounters] = { ...this[kCounters], ...state.counters };
|
|
306
310
|
|
|
307
311
|
if (state.execution) {
|
|
308
|
-
exec.execution
|
|
312
|
+
exec.set('execution', new ActivityExecution(this, this.context).recover(state.execution));
|
|
309
313
|
}
|
|
310
314
|
|
|
311
315
|
this.broker.recover(state.broker);
|
|
@@ -332,7 +336,7 @@ Activity.prototype.resume = function resume() {
|
|
|
332
336
|
|
|
333
337
|
Activity.prototype.discard = function discard(discardContent) {
|
|
334
338
|
if (!this.status) return this._runDiscard(discardContent);
|
|
335
|
-
const execution = this[kExec].execution;
|
|
339
|
+
const execution = this[kExec].get('execution');
|
|
336
340
|
if (execution && !execution.completed) return execution.discard();
|
|
337
341
|
|
|
338
342
|
this._deactivateRunConsumers();
|
|
@@ -347,11 +351,13 @@ Activity.prototype.addInboundListeners = function addInboundListeners() {
|
|
|
347
351
|
const onInboundEvent = this._onInboundEvent.bind(this);
|
|
348
352
|
const triggerConsumerTag = `_inbound-${this.id}`;
|
|
349
353
|
for (const trigger of this[kFlows].inboundTriggers) {
|
|
350
|
-
if (trigger.isSequenceFlow)
|
|
354
|
+
if (trigger.isSequenceFlow) {
|
|
351
355
|
trigger.broker.subscribeTmp('event', 'flow.#', onInboundEvent, { noAck: true, consumerTag: triggerConsumerTag });
|
|
352
|
-
else if (this.isForCompensation)
|
|
356
|
+
} else if (this.isForCompensation) {
|
|
353
357
|
trigger.broker.subscribeTmp('event', 'association.#', onInboundEvent, { noAck: true, consumerTag: triggerConsumerTag });
|
|
354
|
-
else
|
|
358
|
+
} else {
|
|
359
|
+
trigger.broker.subscribeTmp('event', 'activity.#', onInboundEvent, { noAck: true, consumerTag: triggerConsumerTag });
|
|
360
|
+
}
|
|
355
361
|
}
|
|
356
362
|
};
|
|
357
363
|
|
|
@@ -387,7 +393,7 @@ Activity.prototype.evaluateOutbound = function evaluateOutbound(fromMessage, dis
|
|
|
387
393
|
};
|
|
388
394
|
|
|
389
395
|
Activity.prototype.getApi = function getApi(message) {
|
|
390
|
-
const execution = this[kExec].execution;
|
|
396
|
+
const execution = this[kExec].get('execution');
|
|
391
397
|
if (execution && !execution.completed) return execution.getApi(message);
|
|
392
398
|
return ActivityApi(this.broker, message || this[kStateMessage]);
|
|
393
399
|
};
|
|
@@ -398,8 +404,9 @@ Activity.prototype.getActivityById = function getActivityById(elementId) {
|
|
|
398
404
|
|
|
399
405
|
Activity.prototype._runDiscard = function runDiscard(discardContent) {
|
|
400
406
|
const exec = this[kExec];
|
|
401
|
-
const executionId =
|
|
402
|
-
exec.
|
|
407
|
+
const executionId = exec.get('initExecutionId') || getUniqueId(this.id);
|
|
408
|
+
exec.set('executionId', executionId);
|
|
409
|
+
exec.delete('initExecutionId');
|
|
403
410
|
|
|
404
411
|
this._consumeApi();
|
|
405
412
|
|
|
@@ -414,7 +421,7 @@ Activity.prototype._discardRun = function discardRun() {
|
|
|
414
421
|
const status = this.status;
|
|
415
422
|
if (!status) return;
|
|
416
423
|
|
|
417
|
-
const execution = this[kExec].execution;
|
|
424
|
+
const execution = this[kExec].get('execution');
|
|
418
425
|
if (execution && !execution.completed) return;
|
|
419
426
|
|
|
420
427
|
switch (status) {
|
|
@@ -495,42 +502,50 @@ Activity.prototype._onInbound = function onInbound(routingKey, message) {
|
|
|
495
502
|
|
|
496
503
|
Activity.prototype._onJoinInbound = function onJoinInbound(routingKey, message) {
|
|
497
504
|
const { content } = message;
|
|
498
|
-
const {
|
|
499
|
-
|
|
505
|
+
const { inboundJoinFlows, inboundTriggers } = this[kFlows];
|
|
506
|
+
let alreadyTouched = false;
|
|
507
|
+
|
|
508
|
+
const touched = new Set();
|
|
509
|
+
|
|
510
|
+
let taken;
|
|
511
|
+
for (const msg of inboundJoinFlows) {
|
|
512
|
+
const flowId = msg.content.id;
|
|
513
|
+
touched.add(flowId);
|
|
514
|
+
if (flowId === content.id) {
|
|
515
|
+
alreadyTouched = true;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
500
518
|
|
|
501
|
-
inboundJoinFlows.
|
|
519
|
+
inboundJoinFlows.add(message);
|
|
502
520
|
|
|
503
|
-
if (
|
|
521
|
+
if (alreadyTouched) return;
|
|
504
522
|
|
|
505
|
-
const
|
|
506
|
-
if (
|
|
507
|
-
const remaining = inboundSequenceFlows.filter((inb, i, list) => list.indexOf(inb) === i).length - inboundJoinFlows.length;
|
|
523
|
+
const remaining = inboundTriggers.length - touched.size - 1;
|
|
524
|
+
if (remaining) {
|
|
508
525
|
return this.logger.debug(`<${this.id}> inbound ${message.content.action} from <${message.content.id}>, ${remaining} remaining`);
|
|
509
526
|
}
|
|
510
527
|
|
|
511
|
-
const
|
|
512
|
-
|
|
513
|
-
let taken;
|
|
514
|
-
const inbound = evaluatedInbound.map((im) => {
|
|
528
|
+
const inbound = [];
|
|
529
|
+
for (const im of inboundJoinFlows) {
|
|
515
530
|
if (im.fields.routingKey === 'flow.take') taken = true;
|
|
516
531
|
im.ack();
|
|
517
|
-
|
|
518
|
-
}
|
|
532
|
+
inbound.push(cloneContent(im.content));
|
|
533
|
+
}
|
|
519
534
|
|
|
520
|
-
|
|
535
|
+
const discardSequence = new Set();
|
|
521
536
|
if (!taken) {
|
|
522
|
-
|
|
523
|
-
for (const im of evaluatedInbound) {
|
|
537
|
+
for (const im of inboundJoinFlows) {
|
|
524
538
|
if (!im.content.discardSequence) continue;
|
|
525
539
|
for (const sourceId of im.content.discardSequence) {
|
|
526
|
-
|
|
540
|
+
discardSequence.add(sourceId);
|
|
527
541
|
}
|
|
528
542
|
}
|
|
529
543
|
}
|
|
530
544
|
|
|
545
|
+
inboundJoinFlows.clear();
|
|
531
546
|
this.broker.cancel('_run-on-inbound');
|
|
532
547
|
|
|
533
|
-
if (!taken) return this._runDiscard({ inbound, discardSequence });
|
|
548
|
+
if (!taken) return this._runDiscard({ inbound, discardSequence: [...discardSequence] });
|
|
534
549
|
return this.run({ inbound });
|
|
535
550
|
};
|
|
536
551
|
|
|
@@ -604,7 +619,7 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
|
|
|
604
619
|
|
|
605
620
|
this.status = 'entered';
|
|
606
621
|
if (!isRedelivered) {
|
|
607
|
-
this[kExec].execution
|
|
622
|
+
this[kExec].delete('execution');
|
|
608
623
|
if (this.extensions) this.extensions.activate(cloneMessage(message));
|
|
609
624
|
this._publishEvent('enter', content, { correlationId });
|
|
610
625
|
}
|
|
@@ -614,7 +629,7 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
|
|
|
614
629
|
this.logger.debug(`<${id}> discard`, isRedelivered ? 'redelivered' : '');
|
|
615
630
|
|
|
616
631
|
this.status = 'discard';
|
|
617
|
-
this[kExec].execution
|
|
632
|
+
this[kExec].delete('execution');
|
|
618
633
|
|
|
619
634
|
if (this.extensions) this.extensions.activate(cloneMessage(message));
|
|
620
635
|
|
|
@@ -647,11 +662,11 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
|
|
|
647
662
|
|
|
648
663
|
const exec = this[kExec];
|
|
649
664
|
if (isRedelivered && this.extensions) this.extensions.activate(cloneMessage(message));
|
|
650
|
-
if (!exec.execution) exec.execution
|
|
665
|
+
if (!exec.has('execution')) exec.set('execution', new ActivityExecution(this, this.context));
|
|
651
666
|
this.broker
|
|
652
667
|
.getQueue('execution-q')
|
|
653
668
|
.assertConsumer(this[kMessageHandlers].onExecutionMessage, { exclusive: true, consumerTag: '_activity-execution' });
|
|
654
|
-
return exec.execution.execute(message);
|
|
669
|
+
return exec.get('execution').execute(message);
|
|
655
670
|
}
|
|
656
671
|
case 'run.end': {
|
|
657
672
|
this.logger.debug(`<${id}> end`, isRedelivered ? 'redelivered' : '');
|
|
@@ -902,7 +917,7 @@ Activity.prototype._onStop = function onStop(message) {
|
|
|
902
917
|
};
|
|
903
918
|
|
|
904
919
|
Activity.prototype._consumeApi = function consumeApi() {
|
|
905
|
-
const executionId = this[kExec].executionId;
|
|
920
|
+
const executionId = this[kExec].get('executionId');
|
|
906
921
|
if (!executionId) return;
|
|
907
922
|
const broker = this.broker;
|
|
908
923
|
broker.cancel('_activity-api');
|
|
@@ -14,7 +14,7 @@ function ActivityExecution(activity, context) {
|
|
|
14
14
|
this.context = context;
|
|
15
15
|
this.id = activity.id;
|
|
16
16
|
this.broker = activity.broker;
|
|
17
|
-
this[kPostponed] =
|
|
17
|
+
this[kPostponed] = new Set();
|
|
18
18
|
this[kCompleted] = false;
|
|
19
19
|
this[kExecuteQ] = this.broker.assertQueue('execute-q', { durable: true, autoDelete: false });
|
|
20
20
|
|
|
@@ -43,7 +43,7 @@ ActivityExecution.prototype.execute = function execute(executeMessage) {
|
|
|
43
43
|
}));
|
|
44
44
|
|
|
45
45
|
if (executeMessage.fields.redelivered) {
|
|
46
|
-
this[kPostponed].
|
|
46
|
+
this[kPostponed].clear();
|
|
47
47
|
this._debug('resume execution');
|
|
48
48
|
|
|
49
49
|
if (!this.source) this.source = new this.activity.Behaviour(this.activity, this.context);
|
|
@@ -108,11 +108,12 @@ ActivityExecution.prototype.getApi = function getApi(apiMessage) {
|
|
|
108
108
|
const api = ActivityApi(self.broker, apiMessage);
|
|
109
109
|
|
|
110
110
|
api.getExecuting = function getExecuting() {
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
const result = [];
|
|
112
|
+
for (const msg of self[kPostponed]) {
|
|
113
|
+
if (msg.content.executionId === apiMessage.content.executionId) continue;
|
|
113
114
|
result.push(self.getApi(msg));
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
116
117
|
};
|
|
117
118
|
|
|
118
119
|
return api;
|
|
@@ -124,7 +125,10 @@ ActivityExecution.prototype.passthrough = function passthrough(executeMessage) {
|
|
|
124
125
|
};
|
|
125
126
|
|
|
126
127
|
ActivityExecution.prototype.getPostponed = function getPostponed() {
|
|
127
|
-
let apis =
|
|
128
|
+
let apis = [];
|
|
129
|
+
for (const msg of this[kPostponed]) {
|
|
130
|
+
apis.push(this.getApi(msg));
|
|
131
|
+
}
|
|
128
132
|
if (!this.activity.isSubProcess || !this.source) return apis;
|
|
129
133
|
apis = apis.concat(this.source.getPostponed());
|
|
130
134
|
return apis;
|
|
@@ -139,7 +143,7 @@ ActivityExecution.prototype.getState = function getState() {
|
|
|
139
143
|
};
|
|
140
144
|
|
|
141
145
|
ActivityExecution.prototype.recover = function recover(state) {
|
|
142
|
-
this[kPostponed].
|
|
146
|
+
this[kPostponed].clear();
|
|
143
147
|
|
|
144
148
|
if (!state) return this;
|
|
145
149
|
if ('completed' in state) this[kCompleted] = state.completed;
|
|
@@ -174,7 +178,7 @@ ActivityExecution.prototype._onExecuteMessage = function onExecuteMessage(routin
|
|
|
174
178
|
|
|
175
179
|
switch (routingKey) {
|
|
176
180
|
case 'execute.resume.execution': {
|
|
177
|
-
if (!this[kPostponed].
|
|
181
|
+
if (!this[kPostponed].size) return this.broker.publish('execution', 'execute.start', cloneContent(this[kExecuteMessage].content));
|
|
178
182
|
break;
|
|
179
183
|
}
|
|
180
184
|
case 'execute.cancel':
|
|
@@ -215,22 +219,27 @@ ActivityExecution.prototype._onExecuteMessage = function onExecuteMessage(routin
|
|
|
215
219
|
ActivityExecution.prototype._onStateChangeMessage = function onStateChangeMessage(message) {
|
|
216
220
|
const { ignoreIfExecuting, executionId } = message.content;
|
|
217
221
|
const postponed = this[kPostponed];
|
|
218
|
-
|
|
222
|
+
|
|
219
223
|
let previousMsg;
|
|
220
|
-
|
|
224
|
+
for (const msg of postponed) {
|
|
225
|
+
if (msg.content.executionId === executionId) previousMsg = msg;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (previousMsg) {
|
|
221
229
|
if (ignoreIfExecuting) {
|
|
222
230
|
message.ack();
|
|
223
231
|
return false;
|
|
224
232
|
}
|
|
225
233
|
|
|
226
|
-
|
|
234
|
+
postponed.delete(previousMsg);
|
|
235
|
+
postponed.add(message);
|
|
227
236
|
previousMsg.ack();
|
|
228
237
|
|
|
238
|
+
return true;
|
|
239
|
+
} else {
|
|
240
|
+
postponed.add(message);
|
|
229
241
|
return true;
|
|
230
242
|
}
|
|
231
|
-
|
|
232
|
-
postponed.push(message);
|
|
233
|
-
return true;
|
|
234
243
|
};
|
|
235
244
|
|
|
236
245
|
ActivityExecution.prototype._onExecutionCompleted = function onExecutionCompleted(message) {
|
|
@@ -242,8 +251,11 @@ ActivityExecution.prototype._onExecutionCompleted = function onExecutionComplete
|
|
|
242
251
|
if (!isRootScope) {
|
|
243
252
|
this._debug('completed sub execution');
|
|
244
253
|
if (!keep) message.ack();
|
|
245
|
-
if (postponed.
|
|
246
|
-
|
|
254
|
+
if (postponed.size === 1) {
|
|
255
|
+
const onlyMessage = postponed.values().next().value;
|
|
256
|
+
if (onlyMessage.content.isRootScope && !onlyMessage.content.preventComplete) {
|
|
257
|
+
return this.broker.publish('execution', 'execute.completed', cloneContent(onlyMessage.content));
|
|
258
|
+
}
|
|
247
259
|
}
|
|
248
260
|
return;
|
|
249
261
|
}
|
|
@@ -256,7 +268,7 @@ ActivityExecution.prototype._onExecutionCompleted = function onExecutionComplete
|
|
|
256
268
|
this.deactivate();
|
|
257
269
|
|
|
258
270
|
const subApis = this.getPostponed();
|
|
259
|
-
postponed.
|
|
271
|
+
postponed.clear();
|
|
260
272
|
for (const api of subApis) api.discard();
|
|
261
273
|
|
|
262
274
|
this._publishExecutionCompleted('completed', { ...postponedMsg.content, ...message.content }, message.properties.correlationId);
|
|
@@ -271,8 +283,11 @@ ActivityExecution.prototype._onExecutionDiscarded = function onExecutionDiscarde
|
|
|
271
283
|
const correlationId = message.properties.correlationId;
|
|
272
284
|
if (!error && !isRootScope) {
|
|
273
285
|
message.ack();
|
|
274
|
-
if (postponed.
|
|
275
|
-
|
|
286
|
+
if (postponed.size === 1) {
|
|
287
|
+
const onlyMessage = postponed.values().next().value;
|
|
288
|
+
if (onlyMessage.content.isRootScope) {
|
|
289
|
+
return this.broker.publish('execution', 'execute.discard', onlyMessage.content, { correlationId });
|
|
290
|
+
}
|
|
276
291
|
}
|
|
277
292
|
return;
|
|
278
293
|
}
|
|
@@ -282,7 +297,7 @@ ActivityExecution.prototype._onExecutionDiscarded = function onExecutionDiscarde
|
|
|
282
297
|
this.deactivate();
|
|
283
298
|
|
|
284
299
|
const subApis = this.getPostponed();
|
|
285
|
-
postponed.
|
|
300
|
+
postponed.clear();
|
|
286
301
|
for (const api of subApis) api.discard();
|
|
287
302
|
|
|
288
303
|
this._publishExecutionCompleted(discardType, cloneContent(message.content), correlationId);
|
|
@@ -310,11 +325,13 @@ ActivityExecution.prototype._ackPostponed = function ackPostponed(completeMessag
|
|
|
310
325
|
const { executionId: eid } = completeMessage.content;
|
|
311
326
|
|
|
312
327
|
const postponed = this[kPostponed];
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
328
|
+
for (const msg of postponed) {
|
|
329
|
+
if (msg.content.executionId === eid) {
|
|
330
|
+
postponed.delete(msg);
|
|
331
|
+
msg.ack();
|
|
332
|
+
return msg;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
318
335
|
};
|
|
319
336
|
|
|
320
337
|
ActivityExecution.prototype._onParentApiMessage = function onParentApiMessage(routingKey, message) {
|
|
@@ -41,7 +41,7 @@ export function Definition(context, options) {
|
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
this[kStopped] = false;
|
|
44
|
-
this[kExec] =
|
|
44
|
+
this[kExec] = new Map();
|
|
45
45
|
|
|
46
46
|
const onBrokerReturn = this._onBrokerReturnFn.bind(this);
|
|
47
47
|
this[kMessageHandlers] = {
|
|
@@ -71,12 +71,12 @@ Object.defineProperties(Definition.prototype, {
|
|
|
71
71
|
},
|
|
72
72
|
execution: {
|
|
73
73
|
get() {
|
|
74
|
-
return this[kExec].execution;
|
|
74
|
+
return this[kExec].get('execution');
|
|
75
75
|
},
|
|
76
76
|
},
|
|
77
77
|
executionId: {
|
|
78
78
|
get() {
|
|
79
|
-
return this[kExec].executionId;
|
|
79
|
+
return this[kExec].get('executionId');
|
|
80
80
|
},
|
|
81
81
|
},
|
|
82
82
|
isRunning: {
|
|
@@ -97,7 +97,8 @@ Object.defineProperties(Definition.prototype, {
|
|
|
97
97
|
},
|
|
98
98
|
activityStatus: {
|
|
99
99
|
get() {
|
|
100
|
-
|
|
100
|
+
const execution = this[kExec].get('execution');
|
|
101
|
+
return (execution && execution.activityStatus) || 'idle';
|
|
101
102
|
},
|
|
102
103
|
},
|
|
103
104
|
});
|
|
@@ -115,7 +116,8 @@ Definition.prototype.run = function run(optionsOrCallback, optionalCallback) {
|
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
const exec = this[kExec];
|
|
118
|
-
|
|
119
|
+
const executionId = getUniqueId(this.id);
|
|
120
|
+
exec.set('executionId', executionId);
|
|
119
121
|
const content = this._createMessage({ ...runOptions });
|
|
120
122
|
|
|
121
123
|
const broker = this.broker;
|
|
@@ -123,7 +125,7 @@ Definition.prototype.run = function run(optionsOrCallback, optionalCallback) {
|
|
|
123
125
|
broker.publish('run', 'run.start', cloneContent(content));
|
|
124
126
|
broker.publish('run', 'run.execute', cloneContent(content));
|
|
125
127
|
|
|
126
|
-
this.logger.debug(`<${
|
|
128
|
+
this.logger.debug(`<${executionId} (${this.id})> run`);
|
|
127
129
|
|
|
128
130
|
this._activateRunConsumers();
|
|
129
131
|
|
|
@@ -171,7 +173,7 @@ Definition.prototype.recover = function recover(state) {
|
|
|
171
173
|
this[kStatus] = state.status;
|
|
172
174
|
|
|
173
175
|
const exec = this[kExec];
|
|
174
|
-
exec.executionId
|
|
176
|
+
exec.set('executionId', state.executionId);
|
|
175
177
|
if (state.counters) {
|
|
176
178
|
this[kCounters] = { ...this[kCounters], ...state.counters };
|
|
177
179
|
}
|
|
@@ -179,7 +181,7 @@ Definition.prototype.recover = function recover(state) {
|
|
|
179
181
|
this.environment.recover(state.environment);
|
|
180
182
|
|
|
181
183
|
if (state.execution) {
|
|
182
|
-
exec.execution
|
|
184
|
+
exec.set('execution', new DefinitionExecution(this, this.context).recover(state.execution));
|
|
183
185
|
}
|
|
184
186
|
|
|
185
187
|
this.broker.recover(state.broker);
|
|
@@ -350,7 +352,7 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
|
|
|
350
352
|
this[kStatus] = 'entered';
|
|
351
353
|
if (fields.redelivered) break;
|
|
352
354
|
|
|
353
|
-
exec.execution
|
|
355
|
+
exec.delete('execution');
|
|
354
356
|
this._publishEvent('enter', content);
|
|
355
357
|
break;
|
|
356
358
|
}
|
|
@@ -363,7 +365,8 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
|
|
|
363
365
|
case 'run.execute': {
|
|
364
366
|
this[kStatus] = 'executing';
|
|
365
367
|
const executeMessage = cloneMessage(message);
|
|
366
|
-
|
|
368
|
+
let execution = exec.get('execution');
|
|
369
|
+
if (fields.redelivered && !execution) {
|
|
367
370
|
executeMessage.fields.redelivered = undefined;
|
|
368
371
|
}
|
|
369
372
|
this[kExecuteMessage] = message;
|
|
@@ -372,13 +375,16 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
|
|
|
372
375
|
consumerTag: '_definition-execution',
|
|
373
376
|
});
|
|
374
377
|
|
|
375
|
-
|
|
378
|
+
if (!execution) {
|
|
379
|
+
execution = new DefinitionExecution(this, this.context);
|
|
380
|
+
exec.set('execution', execution);
|
|
381
|
+
}
|
|
376
382
|
|
|
377
383
|
if (executeMessage.fields.redelivered) {
|
|
378
384
|
this._publishEvent('resume', content);
|
|
379
385
|
}
|
|
380
386
|
|
|
381
|
-
return
|
|
387
|
+
return execution.execute(executeMessage);
|
|
382
388
|
}
|
|
383
389
|
case 'run.end': {
|
|
384
390
|
if (this[kStatus] === 'end') break;
|
|
@@ -502,7 +508,7 @@ Definition.prototype._onBrokerReturnFn = function onBrokerReturn(message) {
|
|
|
502
508
|
};
|
|
503
509
|
|
|
504
510
|
Definition.prototype._reset = function reset() {
|
|
505
|
-
this[kExec].executionId
|
|
511
|
+
this[kExec].delete('executionId');
|
|
506
512
|
this._deactivateRunConsumers();
|
|
507
513
|
this.broker.purgeQueue('run-q');
|
|
508
514
|
this.broker.purgeQueue('execution-q');
|