bpmn-elements 7.0.0 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/dist/src/Context.js +50 -40
- package/dist/src/Environment.js +39 -19
- package/dist/src/MessageFormatter.js +11 -11
- package/dist/src/activity/Activity.js +106 -106
- package/dist/src/activity/ActivityExecution.js +37 -37
- package/dist/src/activity/Message.js +2 -2
- package/dist/src/activity/Signal.js +2 -2
- package/dist/src/definition/Definition.js +50 -50
- package/dist/src/definition/DefinitionExecution.js +114 -125
- package/dist/src/eventDefinitions/CancelEventDefinition.js +16 -16
- package/dist/src/eventDefinitions/CompensateEventDefinition.js +24 -24
- package/dist/src/eventDefinitions/ConditionalEventDefinition.js +8 -8
- package/dist/src/eventDefinitions/ErrorEventDefinition.js +26 -26
- package/dist/src/eventDefinitions/EscalationEventDefinition.js +20 -20
- package/dist/src/eventDefinitions/EventDefinitionExecution.js +14 -14
- package/dist/src/eventDefinitions/LinkEventDefinition.js +15 -15
- package/dist/src/eventDefinitions/MessageEventDefinition.js +23 -23
- package/dist/src/eventDefinitions/SignalEventDefinition.js +24 -24
- package/dist/src/eventDefinitions/TimerEventDefinition.js +76 -53
- package/dist/src/events/BoundaryEvent.js +67 -38
- package/dist/src/events/EndEvent.js +3 -3
- package/dist/src/events/IntermediateCatchEvent.js +3 -3
- package/dist/src/events/IntermediateThrowEvent.js +3 -3
- package/dist/src/events/StartEvent.js +9 -9
- package/dist/src/flows/Association.js +7 -7
- package/dist/src/flows/MessageFlow.js +9 -9
- package/dist/src/flows/SequenceFlow.js +7 -7
- package/dist/src/gateways/EventBasedGateway.js +11 -11
- package/dist/src/io/InputOutputSpecification.js +4 -4
- package/dist/src/io/Properties.js +9 -9
- package/dist/src/process/Process.js +64 -61
- package/dist/src/process/ProcessExecution.js +93 -90
- package/dist/src/tasks/ReceiveTask.js +16 -16
- package/dist/src/tasks/SubProcess.js +16 -18
- package/package.json +15 -16
- package/src/Context.js +48 -40
- package/src/Environment.js +48 -20
- package/src/EventBroker.js +1 -1
- package/src/MessageFormatter.js +11 -11
- package/src/activity/Activity.js +99 -100
- package/src/activity/ActivityExecution.js +35 -35
- package/src/activity/Message.js +1 -1
- package/src/activity/Signal.js +1 -1
- package/src/definition/Definition.js +51 -50
- package/src/definition/DefinitionExecution.js +111 -113
- package/src/eventDefinitions/CancelEventDefinition.js +16 -16
- package/src/eventDefinitions/CompensateEventDefinition.js +25 -24
- package/src/eventDefinitions/ConditionalEventDefinition.js +8 -8
- package/src/eventDefinitions/ErrorEventDefinition.js +26 -26
- package/src/eventDefinitions/EscalationEventDefinition.js +20 -20
- package/src/eventDefinitions/EventDefinitionExecution.js +14 -14
- package/src/eventDefinitions/LinkEventDefinition.js +15 -15
- package/src/eventDefinitions/MessageEventDefinition.js +23 -23
- package/src/eventDefinitions/SignalEventDefinition.js +24 -24
- package/src/eventDefinitions/TimerEventDefinition.js +61 -44
- package/src/events/BoundaryEvent.js +53 -36
- package/src/events/EndEvent.js +3 -3
- package/src/events/IntermediateCatchEvent.js +3 -3
- package/src/events/IntermediateThrowEvent.js +3 -3
- package/src/events/StartEvent.js +9 -9
- package/src/flows/Association.js +7 -7
- package/src/flows/MessageFlow.js +9 -9
- package/src/flows/SequenceFlow.js +7 -7
- package/src/gateways/EventBasedGateway.js +11 -11
- package/src/io/BpmnIO.js +5 -1
- package/src/io/InputOutputSpecification.js +4 -4
- package/src/io/Properties.js +9 -9
- package/src/process/Process.js +62 -58
- package/src/process/ProcessExecution.js +86 -88
- package/src/tasks/ReceiveTask.js +16 -16
- package/src/tasks/SubProcess.js +16 -16
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {ActivityApi} from '../Api';
|
|
2
2
|
import {cloneContent, cloneMessage} from '../messageHelper';
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
4
|
+
const kCompleted = Symbol.for('completed');
|
|
5
|
+
const kExecuteQ = Symbol.for('executeQ');
|
|
6
|
+
const kExecuteMessage = Symbol.for('executeMessage');
|
|
7
|
+
const kMessageHandlers = Symbol.for('messageHandlers');
|
|
8
|
+
const kPostponed = Symbol.for('postponed');
|
|
9
9
|
|
|
10
10
|
export default ActivityExecution;
|
|
11
11
|
|
|
@@ -14,11 +14,11 @@ function ActivityExecution(activity, context) {
|
|
|
14
14
|
this.context = context;
|
|
15
15
|
this.id = activity.id;
|
|
16
16
|
this.broker = activity.broker;
|
|
17
|
-
this[
|
|
18
|
-
this[
|
|
19
|
-
this[
|
|
17
|
+
this[kPostponed] = [];
|
|
18
|
+
this[kCompleted] = false;
|
|
19
|
+
this[kExecuteQ] = this.broker.assertQueue('execute-q', {durable: true, autoDelete: false});
|
|
20
20
|
|
|
21
|
-
this[
|
|
21
|
+
this[kMessageHandlers] = {
|
|
22
22
|
onParentApiMessage: this._onParentApiMessage.bind(this),
|
|
23
23
|
onExecuteMessage: this._onExecuteMessage.bind(this),
|
|
24
24
|
};
|
|
@@ -29,7 +29,7 @@ const proto = ActivityExecution.prototype;
|
|
|
29
29
|
Object.defineProperty(proto, 'completed', {
|
|
30
30
|
enumerable: true,
|
|
31
31
|
get() {
|
|
32
|
-
return this[
|
|
32
|
+
return this[kCompleted];
|
|
33
33
|
},
|
|
34
34
|
});
|
|
35
35
|
|
|
@@ -39,14 +39,14 @@ proto.execute = function execute(executeMessage) {
|
|
|
39
39
|
if (!executionId) throw new Error('Execution requires execution id');
|
|
40
40
|
|
|
41
41
|
this.executionId = executionId;
|
|
42
|
-
const initMessage = this[
|
|
42
|
+
const initMessage = this[kExecuteMessage] = cloneMessage(executeMessage, {
|
|
43
43
|
executionId,
|
|
44
44
|
state: 'start',
|
|
45
45
|
isRootScope: true,
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
if (executeMessage.fields.redelivered) {
|
|
49
|
-
this[
|
|
49
|
+
this[kPostponed].splice(0);
|
|
50
50
|
this._debug('resume execution');
|
|
51
51
|
|
|
52
52
|
if (!this.source) this.source = new this.activity.Behaviour(this.activity, this.context);
|
|
@@ -62,21 +62,21 @@ proto.execute = function execute(executeMessage) {
|
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
proto.activate = function activate() {
|
|
65
|
-
if (this[
|
|
65
|
+
if (this[kCompleted]) return;
|
|
66
66
|
|
|
67
67
|
const broker = this.broker;
|
|
68
68
|
const batchSize = this.activity.environment.settings.batchSize || 50;
|
|
69
69
|
broker.bindQueue('execute-q', 'execution', 'execute.#', {priority: 100});
|
|
70
70
|
|
|
71
|
-
const {onExecuteMessage, onParentApiMessage} = this[
|
|
72
|
-
this[
|
|
71
|
+
const {onExecuteMessage, onParentApiMessage} = this[kMessageHandlers];
|
|
72
|
+
this[kExecuteQ].assertConsumer(onExecuteMessage, {
|
|
73
73
|
exclusive: true,
|
|
74
74
|
prefetch: batchSize * 2,
|
|
75
75
|
priority: 100,
|
|
76
76
|
consumerTag: '_activity-execute',
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
-
if (this[
|
|
79
|
+
if (this[kCompleted]) return this.deactivate();
|
|
80
80
|
|
|
81
81
|
broker.subscribeTmp('api', `activity.*.${this.executionId}`, onParentApiMessage, {
|
|
82
82
|
noAck: true,
|
|
@@ -93,15 +93,15 @@ proto.deactivate = function deactivate() {
|
|
|
93
93
|
};
|
|
94
94
|
|
|
95
95
|
proto.discard = function discard() {
|
|
96
|
-
if (this[
|
|
97
|
-
const initMessage = this[
|
|
96
|
+
if (this[kCompleted]) return;
|
|
97
|
+
const initMessage = this[kExecuteMessage];
|
|
98
98
|
if (!initMessage) return this.activity.logger.warn(`<${this.id}> is not executing`);
|
|
99
99
|
this.getApi(initMessage).discard();
|
|
100
100
|
};
|
|
101
101
|
|
|
102
102
|
proto.getApi = function getApi(apiMessage) {
|
|
103
103
|
const self = this;
|
|
104
|
-
if (!apiMessage) apiMessage = this[
|
|
104
|
+
if (!apiMessage) apiMessage = this[kExecuteMessage];
|
|
105
105
|
|
|
106
106
|
if (self.source.getApi) {
|
|
107
107
|
const sourceApi = self.source.getApi(apiMessage);
|
|
@@ -111,7 +111,7 @@ proto.getApi = function getApi(apiMessage) {
|
|
|
111
111
|
const api = ActivityApi(self.broker, apiMessage);
|
|
112
112
|
|
|
113
113
|
api.getExecuting = function getExecuting() {
|
|
114
|
-
return self[
|
|
114
|
+
return self[kPostponed].reduce((result, msg) => {
|
|
115
115
|
if (msg.content.executionId === apiMessage.content.executionId) return result;
|
|
116
116
|
result.push(self.getApi(msg));
|
|
117
117
|
return result;
|
|
@@ -127,14 +127,14 @@ proto.passthrough = function passthrough(executeMessage) {
|
|
|
127
127
|
};
|
|
128
128
|
|
|
129
129
|
proto.getPostponed = function getPostponed() {
|
|
130
|
-
let apis = this[
|
|
130
|
+
let apis = this[kPostponed].map((msg) => this.getApi(msg));
|
|
131
131
|
if (!this.activity.isSubProcess || !this.source) return apis;
|
|
132
132
|
apis = apis.concat(this.source.getPostponed());
|
|
133
133
|
return apis;
|
|
134
134
|
};
|
|
135
135
|
|
|
136
136
|
proto.getState = function getState() {
|
|
137
|
-
const result = {completed: this[
|
|
137
|
+
const result = {completed: this[kCompleted]};
|
|
138
138
|
const source = this.source;
|
|
139
139
|
|
|
140
140
|
if (!source || !source.getState) return result;
|
|
@@ -142,10 +142,10 @@ proto.getState = function getState() {
|
|
|
142
142
|
};
|
|
143
143
|
|
|
144
144
|
proto.recover = function recover(state) {
|
|
145
|
-
this[
|
|
145
|
+
this[kPostponed].splice(0);
|
|
146
146
|
|
|
147
147
|
if (!state) return this;
|
|
148
|
-
if ('completed' in state) this[
|
|
148
|
+
if ('completed' in state) this[kCompleted] = state.completed;
|
|
149
149
|
|
|
150
150
|
const source = this.source = new this.activity.Behaviour(this.activity, this.context);
|
|
151
151
|
if (source.recover) {
|
|
@@ -156,7 +156,7 @@ proto.recover = function recover(state) {
|
|
|
156
156
|
};
|
|
157
157
|
|
|
158
158
|
proto.stop = function stop() {
|
|
159
|
-
const executeMessage = this[
|
|
159
|
+
const executeMessage = this[kExecuteMessage];
|
|
160
160
|
if (!executeMessage) return;
|
|
161
161
|
this.getApi(executeMessage).stop();
|
|
162
162
|
};
|
|
@@ -177,7 +177,7 @@ proto._onExecuteMessage = function onExecuteMessage(routingKey, message) {
|
|
|
177
177
|
|
|
178
178
|
switch (routingKey) {
|
|
179
179
|
case 'execute.resume.execution': {
|
|
180
|
-
if (!this[
|
|
180
|
+
if (!this[kPostponed].length) return this.broker.publish('execution', 'execute.start', cloneContent(this[kExecuteMessage].content));
|
|
181
181
|
break;
|
|
182
182
|
}
|
|
183
183
|
case 'execute.error':
|
|
@@ -215,7 +215,7 @@ proto._onExecuteMessage = function onExecuteMessage(routingKey, message) {
|
|
|
215
215
|
|
|
216
216
|
proto._onStateChangeMessage = function onStateChangeMessage(message) {
|
|
217
217
|
const {ignoreIfExecuting, executionId} = message.content;
|
|
218
|
-
const postponed = this[
|
|
218
|
+
const postponed = this[kPostponed];
|
|
219
219
|
const idx = postponed.findIndex((msg) => msg.content.executionId === executionId);
|
|
220
220
|
let previousMsg;
|
|
221
221
|
if (idx > -1) {
|
|
@@ -237,7 +237,7 @@ proto._onStateChangeMessage = function onStateChangeMessage(message) {
|
|
|
237
237
|
proto._onExecutionCompleted = function onExecutionCompleted(message) {
|
|
238
238
|
const postponedMsg = this._ackPostponed(message);
|
|
239
239
|
if (!postponedMsg) return;
|
|
240
|
-
const postponed = this[
|
|
240
|
+
const postponed = this[kPostponed];
|
|
241
241
|
|
|
242
242
|
const {executionId, keep, isRootScope} = message.content;
|
|
243
243
|
if (!isRootScope) {
|
|
@@ -250,7 +250,7 @@ proto._onExecutionCompleted = function onExecutionCompleted(message) {
|
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
this._debug('completed execution', executionId);
|
|
253
|
-
this[
|
|
253
|
+
this[kCompleted] = true;
|
|
254
254
|
|
|
255
255
|
message.ack(true);
|
|
256
256
|
|
|
@@ -268,7 +268,7 @@ proto._onExecutionDiscarded = function onExecutionDiscarded(message) {
|
|
|
268
268
|
const {isRootScope, error} = message.content;
|
|
269
269
|
if (!isRootScope && !postponedMsg) return;
|
|
270
270
|
|
|
271
|
-
const postponed = this[
|
|
271
|
+
const postponed = this[kPostponed];
|
|
272
272
|
const correlationId = message.properties.correlationId;
|
|
273
273
|
if (!error && !isRootScope) {
|
|
274
274
|
message.ack();
|
|
@@ -294,7 +294,7 @@ proto._onExecutionDiscarded = function onExecutionDiscarded(message) {
|
|
|
294
294
|
};
|
|
295
295
|
|
|
296
296
|
proto._publishExecutionCompleted = function publishExecutionCompleted(completionType, completeContent, correlationId) {
|
|
297
|
-
this[
|
|
297
|
+
this[kCompleted] = true;
|
|
298
298
|
|
|
299
299
|
this.broker.publish('execution', `execution.${completionType}`, {
|
|
300
300
|
...completeContent,
|
|
@@ -305,7 +305,7 @@ proto._publishExecutionCompleted = function publishExecutionCompleted(completion
|
|
|
305
305
|
proto._ackPostponed = function ackPostponed(completeMessage) {
|
|
306
306
|
const {executionId: eid} = completeMessage.content;
|
|
307
307
|
|
|
308
|
-
const postponed = this[
|
|
308
|
+
const postponed = this[kPostponed];
|
|
309
309
|
const idx = postponed.findIndex(({content: c}) => c.executionId === eid);
|
|
310
310
|
if (idx === -1) return;
|
|
311
311
|
const [msg] = postponed.splice(idx, 1);
|
|
@@ -316,9 +316,9 @@ proto._ackPostponed = function ackPostponed(completeMessage) {
|
|
|
316
316
|
proto._onParentApiMessage = function onParentApiMessage(routingKey, message) {
|
|
317
317
|
switch (message.properties.type) {
|
|
318
318
|
case 'error':
|
|
319
|
-
return this[
|
|
319
|
+
return this[kExecuteQ].queueMessage({routingKey: 'execute.error'}, {error: message.content.error});
|
|
320
320
|
case 'discard':
|
|
321
|
-
return this[
|
|
321
|
+
return this[kExecuteQ].queueMessage({routingKey: 'execute.discard'}, cloneContent(this[kExecuteMessage].content));
|
|
322
322
|
case 'stop': {
|
|
323
323
|
return this._onStop(message);
|
|
324
324
|
}
|
|
@@ -345,7 +345,7 @@ proto._debug = function debug(logMessage, executionId) {
|
|
|
345
345
|
|
|
346
346
|
function getExecuteMessage(message) {
|
|
347
347
|
const result = cloneMessage(message, {
|
|
348
|
-
...(message.fields.redelivered
|
|
348
|
+
...(message.fields.redelivered && {isRecovered: true}),
|
|
349
349
|
ignoreIfExecuting: undefined,
|
|
350
350
|
});
|
|
351
351
|
return result;
|
package/src/activity/Message.js
CHANGED
|
@@ -16,7 +16,7 @@ export default function Message(messageDef, context) {
|
|
|
16
16
|
id,
|
|
17
17
|
type,
|
|
18
18
|
messageType: 'message',
|
|
19
|
-
...(name
|
|
19
|
+
...(name && {name: environment.resolveExpression(name, executionMessage)}),
|
|
20
20
|
parent: {...parent},
|
|
21
21
|
};
|
|
22
22
|
}
|
package/src/activity/Signal.js
CHANGED
|
@@ -16,7 +16,7 @@ export default function Signal(signalDef, context) {
|
|
|
16
16
|
id,
|
|
17
17
|
type,
|
|
18
18
|
messageType: 'signal',
|
|
19
|
-
...(name
|
|
19
|
+
...(name && {name: environment.resolveExpression(name, executionMessage)}),
|
|
20
20
|
parent: {...parent},
|
|
21
21
|
};
|
|
22
22
|
}
|
|
@@ -5,14 +5,14 @@ import {getUniqueId, getOptionsAndCallback} from '../shared';
|
|
|
5
5
|
import {makeErrorFromMessage} from '../error/Errors';
|
|
6
6
|
import {cloneMessage, cloneContent} from '../messageHelper';
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
8
|
+
const kConsuming = Symbol.for('consuming');
|
|
9
|
+
const kCounters = Symbol.for('counters');
|
|
10
|
+
const kExec = Symbol.for('execution');
|
|
11
|
+
const kExecuteMessage = Symbol.for('executeMessage');
|
|
12
|
+
const kMessageHandlers = Symbol.for('messageHandlers');
|
|
13
|
+
const kStateMessage = Symbol.for('stateMessage');
|
|
14
|
+
const kStatus = Symbol.for('status');
|
|
15
|
+
const kStopped = Symbol.for('stopped');
|
|
16
16
|
|
|
17
17
|
export default Definition;
|
|
18
18
|
|
|
@@ -21,6 +21,7 @@ export function Definition(context, options) {
|
|
|
21
21
|
if (!context) throw new Error('No context');
|
|
22
22
|
|
|
23
23
|
const {id, name, type = 'definition'} = context;
|
|
24
|
+
|
|
24
25
|
this.id = id;
|
|
25
26
|
this.type = type;
|
|
26
27
|
this.name = name;
|
|
@@ -34,16 +35,16 @@ export function Definition(context, options) {
|
|
|
34
35
|
this.context = context;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
this[
|
|
38
|
+
this[kCounters] = {
|
|
38
39
|
completed: 0,
|
|
39
40
|
discarded: 0,
|
|
40
41
|
};
|
|
41
42
|
|
|
42
|
-
this[
|
|
43
|
-
this[
|
|
43
|
+
this[kStopped] = false;
|
|
44
|
+
this[kExec] = {};
|
|
44
45
|
|
|
45
46
|
const onBrokerReturn = this._onBrokerReturnFn.bind(this);
|
|
46
|
-
this[
|
|
47
|
+
this[kMessageHandlers] = {
|
|
47
48
|
onBrokerReturn,
|
|
48
49
|
onApiMessage: this._onApiMessage.bind(this),
|
|
49
50
|
onRunMessage: this._onRunMessage.bind(this),
|
|
@@ -67,28 +68,28 @@ const proto = Definition.prototype;
|
|
|
67
68
|
Object.defineProperty(proto, 'counters', {
|
|
68
69
|
enumerable: true,
|
|
69
70
|
get() {
|
|
70
|
-
return {...this[
|
|
71
|
+
return {...this[kCounters]};
|
|
71
72
|
},
|
|
72
73
|
});
|
|
73
74
|
|
|
74
75
|
Object.defineProperty(proto, 'execution', {
|
|
75
76
|
enumerable: true,
|
|
76
77
|
get() {
|
|
77
|
-
return this[
|
|
78
|
+
return this[kExec].execution;
|
|
78
79
|
},
|
|
79
80
|
});
|
|
80
81
|
|
|
81
82
|
Object.defineProperty(proto, 'executionId', {
|
|
82
83
|
enumerable: true,
|
|
83
84
|
get() {
|
|
84
|
-
return this[
|
|
85
|
+
return this[kExec].executionId;
|
|
85
86
|
},
|
|
86
87
|
});
|
|
87
88
|
|
|
88
89
|
Object.defineProperty(proto, 'isRunning', {
|
|
89
90
|
enumerable: true,
|
|
90
91
|
get() {
|
|
91
|
-
if (!this[
|
|
92
|
+
if (!this[kConsuming]) return false;
|
|
92
93
|
return !!this.status;
|
|
93
94
|
},
|
|
94
95
|
});
|
|
@@ -96,14 +97,14 @@ Object.defineProperty(proto, 'isRunning', {
|
|
|
96
97
|
Object.defineProperty(proto, 'status', {
|
|
97
98
|
enumerable: true,
|
|
98
99
|
get() {
|
|
99
|
-
return this[
|
|
100
|
+
return this[kStatus];
|
|
100
101
|
},
|
|
101
102
|
});
|
|
102
103
|
|
|
103
104
|
Object.defineProperty(proto, 'stopped', {
|
|
104
105
|
enumerable: true,
|
|
105
106
|
get() {
|
|
106
|
-
return this[
|
|
107
|
+
return this[kStopped];
|
|
107
108
|
},
|
|
108
109
|
});
|
|
109
110
|
|
|
@@ -119,7 +120,7 @@ proto.run = function run(optionsOrCallback, optionalCallback) {
|
|
|
119
120
|
addConsumerCallbacks(this, callback);
|
|
120
121
|
}
|
|
121
122
|
|
|
122
|
-
const exec = this[
|
|
123
|
+
const exec = this[kExec];
|
|
123
124
|
exec.executionId = getUniqueId(this.id);
|
|
124
125
|
const content = this._createMessage({...runOptions});
|
|
125
126
|
|
|
@@ -142,7 +143,7 @@ proto.resume = function resume(callback) {
|
|
|
142
143
|
throw err;
|
|
143
144
|
}
|
|
144
145
|
|
|
145
|
-
this[
|
|
146
|
+
this[kStopped] = false;
|
|
146
147
|
if (!this.status) return this;
|
|
147
148
|
|
|
148
149
|
if (callback) {
|
|
@@ -161,13 +162,13 @@ proto.recover = function recover(state) {
|
|
|
161
162
|
if (this.isRunning) throw new Error('cannot recover running definition');
|
|
162
163
|
if (!state) return this;
|
|
163
164
|
|
|
164
|
-
this[
|
|
165
|
-
this[
|
|
165
|
+
this[kStopped] = !!state.stopped;
|
|
166
|
+
this[kStatus] = state.status;
|
|
166
167
|
|
|
167
|
-
const exec = this[
|
|
168
|
+
const exec = this[kExec];
|
|
168
169
|
exec.executionId = state.executionId;
|
|
169
170
|
if (state.counters) {
|
|
170
|
-
this[
|
|
171
|
+
this[kCounters] = {...this[kCounters], ...state.counters};
|
|
171
172
|
}
|
|
172
173
|
|
|
173
174
|
this.environment.recover(state.environment);
|
|
@@ -254,9 +255,9 @@ proto.getProcessById = function getProcessById(processId) {
|
|
|
254
255
|
};
|
|
255
256
|
|
|
256
257
|
proto.getActivityById = function getActivityById(childId) {
|
|
257
|
-
const
|
|
258
|
-
for (const
|
|
259
|
-
const child =
|
|
258
|
+
const bps = this.getProcesses();
|
|
259
|
+
for (const bp of bps) {
|
|
260
|
+
const child = bp.getActivityById(childId);
|
|
260
261
|
if (child) return child;
|
|
261
262
|
}
|
|
262
263
|
return null;
|
|
@@ -275,7 +276,7 @@ proto.getPostponed = function getPostponed(...args) {
|
|
|
275
276
|
proto.getApi = function getApi(message) {
|
|
276
277
|
const execution = this.execution;
|
|
277
278
|
if (execution) return execution.getApi(message);
|
|
278
|
-
message = message || this[
|
|
279
|
+
message = message || this[kStateMessage];
|
|
279
280
|
if (!message) throw new Error('Definition is not running');
|
|
280
281
|
return DefinitionApi(this.broker, message);
|
|
281
282
|
};
|
|
@@ -307,9 +308,9 @@ proto.stop = function stop() {
|
|
|
307
308
|
};
|
|
308
309
|
|
|
309
310
|
proto._activateRunConsumers = function activateRunConsumers() {
|
|
310
|
-
this[
|
|
311
|
+
this[kConsuming] = true;
|
|
311
312
|
const broker = this.broker;
|
|
312
|
-
const {onApiMessage, onRunMessage} = this[
|
|
313
|
+
const {onApiMessage, onRunMessage} = this[kMessageHandlers];
|
|
313
314
|
broker.subscribeTmp('api', `definition.*.${this.executionId}`, onApiMessage, {
|
|
314
315
|
noAck: true,
|
|
315
316
|
consumerTag: '_definition-api',
|
|
@@ -325,7 +326,7 @@ proto._deactivateRunConsumers = function deactivateRunConsumers() {
|
|
|
325
326
|
broker.cancel('_definition-api');
|
|
326
327
|
broker.cancel('_definition-run');
|
|
327
328
|
broker.cancel('_definition-execution');
|
|
328
|
-
this[
|
|
329
|
+
this[kConsuming] = false;
|
|
329
330
|
};
|
|
330
331
|
|
|
331
332
|
proto._createMessage = function createMessage(override) {
|
|
@@ -344,14 +345,14 @@ proto._onRunMessage = function onRunMessage(routingKey, message) {
|
|
|
344
345
|
return this._onResumeMessage(message);
|
|
345
346
|
}
|
|
346
347
|
|
|
347
|
-
const exec = this[
|
|
348
|
-
this[
|
|
348
|
+
const exec = this[kExec];
|
|
349
|
+
this[kStateMessage] = message;
|
|
349
350
|
|
|
350
351
|
switch (routingKey) {
|
|
351
352
|
case 'run.enter': {
|
|
352
353
|
this.logger.debug(`<${this.executionId} (${this.id})> enter`);
|
|
353
354
|
|
|
354
|
-
this[
|
|
355
|
+
this[kStatus] = 'entered';
|
|
355
356
|
if (fields.redelivered) break;
|
|
356
357
|
|
|
357
358
|
exec.execution = undefined;
|
|
@@ -360,18 +361,18 @@ proto._onRunMessage = function onRunMessage(routingKey, message) {
|
|
|
360
361
|
}
|
|
361
362
|
case 'run.start': {
|
|
362
363
|
this.logger.debug(`<${this.executionId} (${this.id})> start`);
|
|
363
|
-
this[
|
|
364
|
+
this[kStatus] = 'start';
|
|
364
365
|
this._publishEvent('start', content);
|
|
365
366
|
break;
|
|
366
367
|
}
|
|
367
368
|
case 'run.execute': {
|
|
368
|
-
this[
|
|
369
|
+
this[kStatus] = 'executing';
|
|
369
370
|
const executeMessage = cloneMessage(message);
|
|
370
371
|
if (fields.redelivered && !exec.execution) {
|
|
371
372
|
executeMessage.fields.redelivered = undefined;
|
|
372
373
|
}
|
|
373
|
-
this[
|
|
374
|
-
this.broker.getQueue('execution-q').assertConsumer(this[
|
|
374
|
+
this[kExecuteMessage] = message;
|
|
375
|
+
this.broker.getQueue('execution-q').assertConsumer(this[kMessageHandlers].onExecutionMessage, {
|
|
375
376
|
exclusive: true,
|
|
376
377
|
consumerTag: '_definition-execution',
|
|
377
378
|
});
|
|
@@ -385,12 +386,12 @@ proto._onRunMessage = function onRunMessage(routingKey, message) {
|
|
|
385
386
|
return exec.execution.execute(executeMessage);
|
|
386
387
|
}
|
|
387
388
|
case 'run.end': {
|
|
388
|
-
if (this
|
|
389
|
+
if (this[kStatus] === 'end') break;
|
|
389
390
|
|
|
390
|
-
this[
|
|
391
|
+
this[kCounters].completed++;
|
|
391
392
|
|
|
392
393
|
this.logger.debug(`<${this.executionId} (${this.id})> completed`);
|
|
393
|
-
this[
|
|
394
|
+
this[kStatus] = 'end';
|
|
394
395
|
this.broker.publish('run', 'run.leave', content);
|
|
395
396
|
this._publishEvent('end', content);
|
|
396
397
|
break;
|
|
@@ -403,17 +404,17 @@ proto._onRunMessage = function onRunMessage(routingKey, message) {
|
|
|
403
404
|
break;
|
|
404
405
|
}
|
|
405
406
|
case 'run.discarded': {
|
|
406
|
-
if (this
|
|
407
|
+
if (this[kStatus] === 'discarded') break;
|
|
407
408
|
|
|
408
|
-
this[
|
|
409
|
+
this[kCounters].discarded++;
|
|
409
410
|
|
|
410
|
-
this[
|
|
411
|
+
this[kStatus] = 'discarded';
|
|
411
412
|
this.broker.publish('run', 'run.leave', content);
|
|
412
413
|
break;
|
|
413
414
|
}
|
|
414
415
|
case 'run.leave': {
|
|
415
416
|
message.ack();
|
|
416
|
-
this[
|
|
417
|
+
this[kStatus] = undefined;
|
|
417
418
|
this._deactivateRunConsumers();
|
|
418
419
|
|
|
419
420
|
this._publishEvent('leave', this._createMessage());
|
|
@@ -427,7 +428,7 @@ proto._onRunMessage = function onRunMessage(routingKey, message) {
|
|
|
427
428
|
proto._onResumeMessage = function onResumeMessage(message) {
|
|
428
429
|
message.ack();
|
|
429
430
|
|
|
430
|
-
const stateMessage = this[
|
|
431
|
+
const stateMessage = this[kStateMessage];
|
|
431
432
|
|
|
432
433
|
switch (stateMessage.fields.routingKey) {
|
|
433
434
|
case 'run.discarded':
|
|
@@ -465,8 +466,8 @@ proto._onExecutionMessage = function onExecutionMessage(routingKey, message) {
|
|
|
465
466
|
}
|
|
466
467
|
}
|
|
467
468
|
|
|
468
|
-
const executeMessage = this[
|
|
469
|
-
this[
|
|
469
|
+
const executeMessage = this[kExecuteMessage];
|
|
470
|
+
this[kExecuteMessage] = null;
|
|
470
471
|
executeMessage.ack();
|
|
471
472
|
};
|
|
472
473
|
|
|
@@ -488,7 +489,7 @@ proto._publishEvent = function publishEvent(action, content, msgOpts) {
|
|
|
488
489
|
};
|
|
489
490
|
|
|
490
491
|
proto._onStop = function onStop() {
|
|
491
|
-
this[
|
|
492
|
+
this[kStopped] = true;
|
|
492
493
|
this._deactivateRunConsumers();
|
|
493
494
|
return this._publishEvent('stop', this._createMessage());
|
|
494
495
|
};
|
|
@@ -502,7 +503,7 @@ proto._onBrokerReturnFn = function onBrokerReturn(message) {
|
|
|
502
503
|
};
|
|
503
504
|
|
|
504
505
|
proto._reset = function reset() {
|
|
505
|
-
this[
|
|
506
|
+
this[kExec].executionId = undefined;
|
|
506
507
|
this._deactivateRunConsumers();
|
|
507
508
|
this.broker.purgeQueue('run-q');
|
|
508
509
|
this.broker.purgeQueue('execution-q');
|