bpmn-elements 6.0.0 → 8.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/CHANGELOG.md +335 -0
- package/README.md +3 -0
- package/dist/index.js +52 -44
- package/dist/src/Api.js +77 -76
- package/dist/src/Context.js +176 -172
- package/dist/src/Environment.js +110 -102
- package/dist/src/EventBroker.js +89 -88
- package/dist/src/ExtensionsMapper.js +2 -2
- package/dist/src/MessageFormatter.js +164 -95
- package/dist/src/Scripts.js +6 -2
- package/dist/src/activity/Activity.js +1106 -916
- package/dist/src/activity/ActivityExecution.js +342 -297
- package/dist/src/activity/Dummy.js +3 -3
- package/dist/src/definition/Definition.js +498 -444
- package/dist/src/definition/DefinitionExecution.js +710 -408
- package/dist/src/error/Errors.js +17 -7
- package/dist/src/eventDefinitions/CancelEventDefinition.js +190 -150
- package/dist/src/eventDefinitions/CompensateEventDefinition.js +194 -161
- package/dist/src/eventDefinitions/ConditionalEventDefinition.js +197 -135
- package/dist/src/eventDefinitions/ErrorEventDefinition.js +207 -165
- package/dist/src/eventDefinitions/EscalationEventDefinition.js +175 -141
- package/dist/src/eventDefinitions/EventDefinitionExecution.js +157 -129
- package/dist/src/eventDefinitions/LinkEventDefinition.js +174 -149
- package/dist/src/eventDefinitions/MessageEventDefinition.js +213 -176
- package/dist/src/eventDefinitions/SignalEventDefinition.js +203 -161
- package/dist/src/eventDefinitions/TerminateEventDefinition.js +21 -23
- package/dist/src/eventDefinitions/TimerEventDefinition.js +243 -228
- package/dist/src/events/BoundaryEvent.js +180 -144
- package/dist/src/events/EndEvent.js +18 -23
- package/dist/src/events/IntermediateCatchEvent.js +44 -58
- package/dist/src/events/IntermediateThrowEvent.js +18 -23
- package/dist/src/events/StartEvent.js +109 -94
- package/dist/src/flows/Association.js +94 -100
- package/dist/src/flows/MessageFlow.js +86 -103
- package/dist/src/flows/SequenceFlow.js +173 -182
- package/dist/src/gateways/EventBasedGateway.js +88 -84
- package/dist/src/gateways/ExclusiveGateway.js +13 -16
- package/dist/src/gateways/InclusiveGateway.js +11 -14
- package/dist/src/gateways/ParallelGateway.js +11 -14
- package/dist/src/getPropertyValue.js +34 -34
- package/dist/src/io/BpmnIO.js +17 -14
- package/dist/src/io/EnvironmentDataObject.js +33 -29
- package/dist/src/io/EnvironmentDataStore.js +33 -29
- package/dist/src/io/EnvironmentDataStoreReference.js +35 -31
- package/dist/src/io/InputOutputSpecification.js +177 -168
- package/dist/src/io/Properties.js +117 -124
- package/dist/src/messageHelper.js +1 -1
- package/dist/src/process/Process.js +439 -362
- package/dist/src/process/ProcessExecution.js +748 -646
- package/dist/src/shared.js +2 -2
- package/dist/src/tasks/CallActivity.js +160 -0
- package/dist/src/tasks/LoopCharacteristics.js +309 -330
- package/dist/src/tasks/ReceiveTask.js +233 -182
- package/dist/src/tasks/ScriptTask.js +35 -41
- package/dist/src/tasks/ServiceImplementation.js +13 -20
- package/dist/src/tasks/ServiceTask.js +82 -75
- package/dist/src/tasks/SignalTask.js +97 -93
- package/dist/src/tasks/StandardLoopCharacteristics.js +1 -1
- package/dist/src/tasks/SubProcess.js +193 -175
- package/dist/src/tasks/Task.js +17 -19
- package/index.js +2 -0
- package/package.json +15 -15
- package/src/Api.js +65 -59
- package/src/Context.js +145 -140
- package/src/Environment.js +116 -100
- package/src/EventBroker.js +67 -68
- package/src/ExtensionsMapper.js +2 -2
- package/src/MessageFormatter.js +132 -74
- package/src/activity/Activity.js +915 -775
- package/src/activity/ActivityExecution.js +293 -247
- package/src/activity/Dummy.js +2 -2
- package/src/definition/Definition.js +437 -401
- package/src/definition/DefinitionExecution.js +598 -340
- package/src/error/Errors.js +11 -6
- package/src/eventDefinitions/CancelEventDefinition.js +164 -121
- package/src/eventDefinitions/CompensateEventDefinition.js +159 -124
- package/src/eventDefinitions/ConditionalEventDefinition.js +147 -104
- package/src/eventDefinitions/ErrorEventDefinition.js +190 -131
- package/src/eventDefinitions/EscalationEventDefinition.js +139 -101
- package/src/eventDefinitions/EventDefinitionExecution.js +127 -95
- package/src/eventDefinitions/LinkEventDefinition.js +160 -129
- package/src/eventDefinitions/MessageEventDefinition.js +178 -121
- package/src/eventDefinitions/SignalEventDefinition.js +162 -106
- package/src/eventDefinitions/TerminateEventDefinition.js +19 -19
- package/src/eventDefinitions/TimerEventDefinition.js +202 -167
- package/src/events/BoundaryEvent.js +156 -115
- package/src/events/EndEvent.js +15 -18
- package/src/events/IntermediateCatchEvent.js +40 -44
- package/src/events/IntermediateThrowEvent.js +15 -18
- package/src/events/StartEvent.js +84 -50
- package/src/flows/Association.js +98 -112
- package/src/flows/MessageFlow.js +81 -97
- package/src/flows/SequenceFlow.js +146 -160
- package/src/gateways/EventBasedGateway.js +75 -68
- package/src/gateways/ExclusiveGateway.js +8 -13
- package/src/gateways/InclusiveGateway.js +8 -13
- package/src/gateways/ParallelGateway.js +8 -13
- package/src/getPropertyValue.js +34 -33
- package/src/io/BpmnIO.js +20 -15
- package/src/io/EnvironmentDataObject.js +29 -18
- package/src/io/EnvironmentDataStore.js +29 -18
- package/src/io/EnvironmentDataStoreReference.js +31 -20
- package/src/io/InputOutputSpecification.js +154 -157
- package/src/io/Properties.js +95 -97
- package/src/process/Process.js +378 -333
- package/src/process/ProcessExecution.js +603 -553
- package/src/tasks/CallActivity.js +130 -0
- package/src/tasks/LoopCharacteristics.js +290 -289
- package/src/tasks/ReceiveTask.js +174 -107
- package/src/tasks/ScriptTask.js +27 -30
- package/src/tasks/ServiceImplementation.js +13 -18
- package/src/tasks/ServiceTask.js +67 -60
- package/src/tasks/SignalTask.js +77 -52
- package/src/tasks/StandardLoopCharacteristics.js +1 -1
- package/src/tasks/SubProcess.js +184 -157
- package/src/tasks/Task.js +15 -19
|
@@ -1,127 +1,170 @@
|
|
|
1
1
|
import {cloneContent, shiftParent} from '../messageHelper';
|
|
2
|
+
import {ActivityError} from '../error/Errors';
|
|
3
|
+
|
|
4
|
+
const kExecuteMessage = Symbol.for('executeMessage');
|
|
2
5
|
|
|
3
6
|
export default function ConditionalEventDefinition(activity, eventDefinition) {
|
|
4
7
|
const {id, broker, environment, attachedTo} = activity;
|
|
5
|
-
const {type = 'ConditionalEventDefinition', behaviour = {}} = eventDefinition;
|
|
6
|
-
const {debug} = environment.Logger(type.toLowerCase());
|
|
7
|
-
const condition = behaviour.expression;
|
|
8
|
-
const isWaiting = !attachedTo;
|
|
9
8
|
|
|
10
|
-
const
|
|
11
|
-
type,
|
|
12
|
-
condition,
|
|
13
|
-
execute,
|
|
14
|
-
};
|
|
9
|
+
const {type = 'ConditionalEventDefinition', behaviour = {}} = eventDefinition;
|
|
15
10
|
|
|
16
|
-
|
|
11
|
+
this.id = id;
|
|
12
|
+
this.type = type;
|
|
13
|
+
this.isWaiting = !attachedTo;
|
|
14
|
+
this.condition = behaviour.expression;
|
|
15
|
+
this.activity = activity;
|
|
16
|
+
this.environment = environment;
|
|
17
|
+
this.broker = broker;
|
|
18
|
+
this.logger = environment.Logger(type.toLowerCase());
|
|
19
|
+
}
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
const proto = ConditionalEventDefinition.prototype;
|
|
22
|
+
|
|
23
|
+
Object.defineProperty(proto, 'executionId', {
|
|
24
|
+
get() {
|
|
25
|
+
const message = this[kExecuteMessage];
|
|
26
|
+
return message && message.content.executionId;
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
proto.execute = function execute(executeMessage) {
|
|
31
|
+
this[kExecuteMessage] = executeMessage;
|
|
32
|
+
return this.isWaiting ? this.executeWait(executeMessage) : this.executeCatch(executeMessage);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
proto.executeWait = function executeWait(executeMessage) {
|
|
36
|
+
const executeContent = executeMessage.content;
|
|
37
|
+
const {executionId, parent} = executeContent;
|
|
38
|
+
const parentExecutionId = parent.executionId;
|
|
39
|
+
|
|
40
|
+
if (this._evaluateWait(executeMessage)) return;
|
|
41
|
+
|
|
42
|
+
const broker = this.broker;
|
|
43
|
+
const onApiMessage = this._onWaitApiMessage.bind(this);
|
|
44
|
+
broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
|
|
45
|
+
noAck: true,
|
|
46
|
+
consumerTag: `_api-${executionId}`,
|
|
47
|
+
});
|
|
48
|
+
broker.subscribeTmp('api', `activity.signal.${parentExecutionId}`, onApiMessage, {
|
|
49
|
+
noAck: true,
|
|
50
|
+
consumerTag: `_parent-signal-${executionId}`,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const waitContent = cloneContent(executeContent, {
|
|
54
|
+
executionId: parentExecutionId,
|
|
55
|
+
condition: this.condition,
|
|
56
|
+
});
|
|
57
|
+
waitContent.parent = shiftParent(parent);
|
|
58
|
+
|
|
59
|
+
broker.publish('event', 'activity.wait', waitContent);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
proto.executeCatch = function executeCatch(executeMessage) {
|
|
63
|
+
const executeContent = executeMessage.content;
|
|
64
|
+
const {executionId, index} = executeContent;
|
|
65
|
+
|
|
66
|
+
this.broker.subscribeTmp('api', `activity.#.${executionId}`, this._onCatchApiMessage.bind(this), {
|
|
67
|
+
noAck: true,
|
|
68
|
+
consumerTag: `_api-${executionId}_${index}`,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const {id: attachedToId, broker: attachedToBroker} = this.activity.attachedTo;
|
|
72
|
+
|
|
73
|
+
this._debug(`listen for execute completed from <${attachedToId}>`);
|
|
74
|
+
|
|
75
|
+
attachedToBroker.subscribeOnce('execution', 'execute.completed', this._onAttachedCompleted.bind(this), {
|
|
76
|
+
priority: 300,
|
|
77
|
+
consumerTag: `_onend-${executionId}_${index}`,
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
proto._onWaitApiMessage = function onWaitApiMessage(routingKey, message) {
|
|
82
|
+
const messageType = message.properties.type;
|
|
83
|
+
|
|
84
|
+
switch (messageType) {
|
|
85
|
+
case 'signal': {
|
|
86
|
+
return this._evaluateWait(message);
|
|
87
|
+
}
|
|
88
|
+
case 'discard': {
|
|
89
|
+
this._stopWait();
|
|
90
|
+
return this.broker.publish('execution', 'execute.discard', cloneContent(this[kExecuteMessage].content, {state: 'discard'}));
|
|
91
|
+
}
|
|
92
|
+
case 'stop': {
|
|
93
|
+
return this._stopWait();
|
|
94
|
+
}
|
|
20
95
|
}
|
|
96
|
+
};
|
|
21
97
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const {executionId, index} = messageContent;
|
|
27
|
-
messageContent.condition = condition;
|
|
28
|
-
|
|
29
|
-
const apiConsumerTag = `_api-${executionId}_${index}`;
|
|
30
|
-
const endConsumerTag = `_onend-${executionId}_${index}`;
|
|
98
|
+
proto._evaluateWait = function evaluate(message) {
|
|
99
|
+
const executeMessage = this[kExecuteMessage];
|
|
100
|
+
const broker = this.broker, executeContent = executeMessage.content;
|
|
31
101
|
|
|
32
|
-
|
|
102
|
+
try {
|
|
103
|
+
var output = this.environment.resolveExpression(this.condition, message); // eslint-disable-line no-var
|
|
104
|
+
} catch (err) {
|
|
105
|
+
return broker.publish('execution', 'execute.error', cloneContent(executeContent, {error: new ActivityError(err.message, executeMessage, err)}, {mandatory: true}));
|
|
106
|
+
}
|
|
33
107
|
|
|
34
|
-
|
|
35
|
-
attachedToBroker.subscribeOnce('execution', 'execute.completed', onAttachedCompleted, {priority: 300, consumerTag: endConsumerTag});
|
|
108
|
+
this._debug(`condition evaluated to ${!!output}`);
|
|
36
109
|
|
|
37
|
-
|
|
38
|
-
|
|
110
|
+
broker.publish('event', 'activity.condition', cloneContent(executeContent, {
|
|
111
|
+
conditionResult: output,
|
|
112
|
+
}));
|
|
39
113
|
|
|
40
|
-
|
|
41
|
-
|
|
114
|
+
if (!output) return;
|
|
115
|
+
this._stopWait();
|
|
116
|
+
return broker.publish('execution', 'execute.completed', cloneContent(executeContent, {output}));
|
|
117
|
+
};
|
|
42
118
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
119
|
+
proto._stopWait = function stopWait() {
|
|
120
|
+
const broker = this.broker, executionId = this.executionId;
|
|
121
|
+
broker.cancel(`_api-${executionId}`);
|
|
122
|
+
broker.cancel(`_parent-signal-${executionId}`);
|
|
123
|
+
};
|
|
47
124
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
...messageContent,
|
|
51
|
-
output,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
125
|
+
proto._onAttachedCompleted = function onAttachedCompleted(routingKey, message) {
|
|
126
|
+
this._stopCatch();
|
|
55
127
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return broker.publish('execution', 'execute.discard', {...messageContent, state: 'discard'});
|
|
63
|
-
}
|
|
64
|
-
case 'stop': {
|
|
65
|
-
stop();
|
|
66
|
-
return debug(`<${executionId} (${id})> stopped`);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function stop() {
|
|
72
|
-
attachedToBroker.cancel(endConsumerTag);
|
|
73
|
-
broker.cancel(apiConsumerTag);
|
|
74
|
-
}
|
|
128
|
+
const executeMessage = this[kExecuteMessage];
|
|
129
|
+
const broker = this.broker, executeContent = executeMessage.content;
|
|
130
|
+
try {
|
|
131
|
+
var output = this.environment.resolveExpression(this.condition, message); // eslint-disable-line no-var
|
|
132
|
+
} catch (err) {
|
|
133
|
+
return broker.publish('execution', 'execute.error', cloneContent(executeContent, {error: new ActivityError(err.message, executeMessage, err)}, {mandatory: true}));
|
|
75
134
|
}
|
|
76
135
|
|
|
77
|
-
|
|
78
|
-
const messageContent = cloneContent(executeMessage.content);
|
|
79
|
-
messageContent.condition = condition;
|
|
80
|
-
const {executionId, parent} = messageContent;
|
|
81
|
-
const parentExecutionId = parent && parent.executionId;
|
|
82
|
-
|
|
83
|
-
if (evaluate(executeMessage)) return;
|
|
84
|
-
|
|
85
|
-
broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {noAck: true, consumerTag: `_api-${executionId}`});
|
|
86
|
-
broker.subscribeTmp('api', `activity.signal.${parentExecutionId}`, onApiMessage, {noAck: true, consumerTag: `_parent-signal-${executionId}`});
|
|
87
|
-
|
|
88
|
-
broker.publish('event', 'activity.wait', {...cloneContent(messageContent), executionId: parentExecutionId, parent: shiftParent(parent)});
|
|
89
|
-
|
|
90
|
-
function onApiMessage(routingKey, message) {
|
|
91
|
-
const messageType = message.properties.type;
|
|
92
|
-
|
|
93
|
-
switch (messageType) {
|
|
94
|
-
case 'signal': {
|
|
95
|
-
return evaluate(message);
|
|
96
|
-
}
|
|
97
|
-
case 'discard': {
|
|
98
|
-
stop();
|
|
99
|
-
return broker.publish('execution', 'execute.discard', {...messageContent, state: 'discard'});
|
|
100
|
-
}
|
|
101
|
-
case 'stop': {
|
|
102
|
-
stop();
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function evaluate(message) {
|
|
109
|
-
const output = environment.resolveExpression(condition, message);
|
|
110
|
-
debug(`<${executionId} (${id})> condition evaluated to`, !!output);
|
|
136
|
+
this._debug(`condition from <${message.content.executionId}> evaluated to ${!!output}`);
|
|
111
137
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
});
|
|
138
|
+
broker.publish('event', 'activity.condition', cloneContent(executeContent, {
|
|
139
|
+
conditionResult: output,
|
|
140
|
+
}));
|
|
116
141
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
142
|
+
if (output) {
|
|
143
|
+
broker.publish('execution', 'execute.completed', cloneContent(executeContent, {output}));
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
proto._onCatchApiMessage = function onCatchApiMessage(routingKey, message) {
|
|
148
|
+
const messageType = message.properties.type;
|
|
149
|
+
switch (messageType) {
|
|
150
|
+
case 'discard': {
|
|
151
|
+
this._stopCatch();
|
|
152
|
+
this._debug('discarded');
|
|
153
|
+
return this.broker.publish('execution', 'execute.discard', cloneContent(this[kExecuteMessage].content, {state: 'discard'}));
|
|
120
154
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
broker.cancel(`_parent-signal-${executionId}`);
|
|
155
|
+
case 'stop': {
|
|
156
|
+
this._stopCatch();
|
|
157
|
+
return this._debug('stopped');
|
|
125
158
|
}
|
|
126
159
|
}
|
|
127
|
-
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
proto._stopCatch = function stopCatch() {
|
|
163
|
+
const {executionId, index} = this[kExecuteMessage].content;
|
|
164
|
+
this.activity.attachedTo.broker.cancel(`_onend-${executionId}_${index}`);
|
|
165
|
+
this.broker.cancel(`_api-${executionId}_${index}`);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
proto._debug = function debug(msg) {
|
|
169
|
+
this.logger.debug(`<${this.executionId} (${this.activity.id})> ${msg}`);
|
|
170
|
+
};
|
|
@@ -1,160 +1,219 @@
|
|
|
1
1
|
import {brokerSafeId} from '../shared';
|
|
2
2
|
import {cloneContent, shiftParent} from '../messageHelper';
|
|
3
3
|
|
|
4
|
+
const kCompleted = Symbol.for('completed');
|
|
5
|
+
const kMessageQ = Symbol.for('messageQ');
|
|
6
|
+
const kExecuteMessage = Symbol.for('executeMessage');
|
|
7
|
+
const kReferenceElement = Symbol.for('referenceElement');
|
|
8
|
+
const kReferenceInfo = Symbol.for('referenceInfo');
|
|
9
|
+
|
|
4
10
|
export default function ErrorEventDefinition(activity, eventDefinition) {
|
|
5
|
-
const {id, broker, environment,
|
|
11
|
+
const {id, broker, environment, isThrowing} = activity;
|
|
6
12
|
const {type = 'ErrorEventDefinition', behaviour = {}} = eventDefinition;
|
|
7
|
-
const {debug} = environment.Logger(type.toLowerCase());
|
|
8
|
-
const reference = behaviour.errorRef || {name: 'anonymous'};
|
|
9
|
-
const referenceElement = reference.id && getActivityById(reference.id);
|
|
10
|
-
const errorId = referenceElement ? referenceElement.id : 'anonymous';
|
|
11
|
-
const errorQueueName = `error-${brokerSafeId(id)}-${brokerSafeId(errorId)}-q`;
|
|
12
|
-
|
|
13
|
-
if (!isThrowing) setupCatch();
|
|
14
|
-
|
|
15
|
-
const source = {
|
|
16
|
-
type,
|
|
17
|
-
reference: {...reference, referenceType: 'throw'},
|
|
18
|
-
execute: isThrowing ? executeThrow : executeCatch,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
return source;
|
|
22
|
-
|
|
23
|
-
function executeCatch(executeMessage) {
|
|
24
|
-
let completed;
|
|
25
13
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const parentExecutionId = parent && parent.executionId;
|
|
14
|
+
this.id = id;
|
|
15
|
+
this.type = type;
|
|
29
16
|
|
|
30
|
-
|
|
31
|
-
|
|
17
|
+
const reference = this.reference = {
|
|
18
|
+
name: 'anonymous',
|
|
19
|
+
...behaviour.errorRef,
|
|
20
|
+
referenceType: 'throw',
|
|
21
|
+
};
|
|
32
22
|
|
|
33
|
-
|
|
23
|
+
this.isThrowing = isThrowing;
|
|
24
|
+
this.activity = activity;
|
|
25
|
+
this.environment = environment;
|
|
26
|
+
this.broker = broker;
|
|
27
|
+
this.logger = environment.Logger(type.toLowerCase());
|
|
28
|
+
|
|
29
|
+
const referenceElement = this[kReferenceElement] = reference.id && activity.getActivityById(reference.id);
|
|
30
|
+
if (!isThrowing) {
|
|
31
|
+
this[kCompleted] = false;
|
|
32
|
+
const referenceId = referenceElement ? referenceElement.id : 'anonymous';
|
|
33
|
+
const messageQueueName = `${reference.referenceType}-${brokerSafeId(id)}-${brokerSafeId(referenceId)}-q`;
|
|
34
|
+
this[kMessageQ] = broker.assertQueue(messageQueueName, {autoDelete: false, durable: true});
|
|
35
|
+
broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, {durable: true, priority: 300});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
34
38
|
|
|
35
|
-
|
|
39
|
+
const proto = ErrorEventDefinition.prototype;
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
Object.defineProperty(proto, 'executionId', {
|
|
42
|
+
get() {
|
|
43
|
+
const message = this[kExecuteMessage];
|
|
44
|
+
return message && message.content.executionId;
|
|
45
|
+
},
|
|
46
|
+
});
|
|
42
47
|
|
|
43
|
-
|
|
48
|
+
proto.execute = function execute(executeMessage) {
|
|
49
|
+
return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
|
|
50
|
+
};
|
|
44
51
|
|
|
45
|
-
|
|
52
|
+
proto.executeCatch = function executeCatch(executeMessage) {
|
|
53
|
+
this[kExecuteMessage] = executeMessage;
|
|
54
|
+
this[kCompleted] = false;
|
|
46
55
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
parent: shiftParent(parent),
|
|
51
|
-
expect: {...referenceMessage},
|
|
52
|
-
});
|
|
56
|
+
const executeContent = executeMessage.content;
|
|
57
|
+
const {executionId, parent} = executeContent;
|
|
58
|
+
const parentExecutionId = parent && parent.executionId;
|
|
53
59
|
|
|
54
|
-
|
|
55
|
-
const error = message.content.error;
|
|
56
|
-
if (!referenceElement) return catchError(routingKey, message, error);
|
|
60
|
+
const info = this[kReferenceInfo] = this._getReferenceInfo(executeMessage);
|
|
57
61
|
|
|
58
|
-
|
|
62
|
+
this[kMessageQ].consume(this._onThrowApiMessage.bind(this), {
|
|
63
|
+
noAck: true,
|
|
64
|
+
consumerTag: `_onthrow-${executionId}`,
|
|
65
|
+
});
|
|
59
66
|
|
|
60
|
-
|
|
67
|
+
if (this[kCompleted]) return;
|
|
61
68
|
|
|
62
|
-
|
|
63
|
-
}
|
|
69
|
+
this._debug(`expect ${info.description}`);
|
|
64
70
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
71
|
+
const broker = this.broker;
|
|
72
|
+
broker.subscribeTmp('api', `activity.#.${executionId}`, this._onApiMessage.bind(this), {
|
|
73
|
+
noAck: true,
|
|
74
|
+
consumerTag: `_api-${executionId}`,
|
|
75
|
+
});
|
|
68
76
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
if (!this.environment.settings.strict) {
|
|
78
|
+
const expectRoutingKey = `execute.throw.${executionId}`;
|
|
79
|
+
broker.subscribeTmp('execution', expectRoutingKey, this._onErrorMessage.bind(this), {
|
|
80
|
+
noAck: true,
|
|
81
|
+
consumerTag: `_onerror-${executionId}`,
|
|
82
|
+
});
|
|
83
|
+
broker.publish('execution', 'execute.expect', cloneContent(executeContent, {
|
|
84
|
+
expectRoutingKey,
|
|
85
|
+
expect: {...info.message},
|
|
86
|
+
}));
|
|
72
87
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
stop();
|
|
77
|
-
|
|
78
|
-
debug(`<${executionId} (${id})> caught ${description}`);
|
|
79
|
-
broker.publish('event', 'activity.catch', {
|
|
80
|
-
...messageContent,
|
|
81
|
-
source: {
|
|
82
|
-
id: message.content.id,
|
|
83
|
-
type: message.content.type,
|
|
84
|
-
executionId: message.content.executionId,
|
|
85
|
-
},
|
|
86
|
-
error,
|
|
87
|
-
executionId: parentExecutionId,
|
|
88
|
-
parent: shiftParent(executeMessage.content.parent),
|
|
89
|
-
}, {type: 'catch'});
|
|
90
|
-
|
|
91
|
-
return broker.publish('execution', 'execute.completed', {...messageContent, output: error, cancelActivity: true, state: 'catch'});
|
|
92
|
-
}
|
|
88
|
+
if (this[kCompleted]) return this._stop();
|
|
89
|
+
}
|
|
93
90
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
91
|
+
const waitContent = cloneContent(executeContent, {
|
|
92
|
+
executionId: parentExecutionId,
|
|
93
|
+
expect: {...info.message},
|
|
94
|
+
});
|
|
95
|
+
waitContent.parent = shiftParent(parent);
|
|
96
|
+
|
|
97
|
+
broker.publish('event', 'activity.wait', waitContent);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
proto.executeThrow = function executeThrow(executeMessage) {
|
|
101
|
+
const executeContent = executeMessage.content;
|
|
102
|
+
const {executionId, parent} = executeContent;
|
|
103
|
+
|
|
104
|
+
const info = this._getReferenceInfo(executeMessage);
|
|
105
|
+
|
|
106
|
+
this.logger.debug(`<${executionId} (${this.activity.id})> throw ${info.description}`);
|
|
107
|
+
|
|
108
|
+
const broker = this.broker;
|
|
109
|
+
const throwContent = cloneContent(executeContent, {
|
|
110
|
+
executionId: parent.executionId,
|
|
111
|
+
message: {...info.message},
|
|
112
|
+
state: 'throw',
|
|
113
|
+
});
|
|
114
|
+
throwContent.parent = shiftParent(parent);
|
|
115
|
+
|
|
116
|
+
this.broker.publish('event', 'activity.throw', throwContent, {type: 'throw', delegate: true});
|
|
117
|
+
|
|
118
|
+
return broker.publish('execution', 'execute.completed', cloneContent(executeContent, {
|
|
119
|
+
message: {...info.message},
|
|
120
|
+
}));
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
proto._onErrorMessage = function onErrorMessage(routingKey, message) {
|
|
124
|
+
const error = message.content.error;
|
|
125
|
+
if (!this[kReferenceElement]) return this._catchError(routingKey, message, error);
|
|
126
|
+
|
|
127
|
+
if (!error) return;
|
|
128
|
+
|
|
129
|
+
const info = this[kReferenceInfo];
|
|
130
|
+
if (('' + error.code) !== ('' + info.message.code)) return;
|
|
131
|
+
|
|
132
|
+
return this._catchError(routingKey, message, error);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
proto._onThrowApiMessage = function onThrowApiMessage(routingKey, message) {
|
|
136
|
+
const error = message.content.message;
|
|
137
|
+
if (!this[kReferenceElement]) return this._catchError(routingKey, message, error);
|
|
138
|
+
|
|
139
|
+
const info = this[kReferenceInfo];
|
|
140
|
+
if (info.message.id !== (error && error.id)) return;
|
|
141
|
+
return this._catchError(routingKey, message, error);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
proto._catchError = function catchError(routingKey, message, error) {
|
|
145
|
+
this[kCompleted] = true;
|
|
146
|
+
|
|
147
|
+
this._stop();
|
|
148
|
+
|
|
149
|
+
this._debug(`caught ${this[kReferenceInfo].description}`);
|
|
150
|
+
|
|
151
|
+
const executeContent = this[kExecuteMessage].content;
|
|
152
|
+
const parent = executeContent.parent;
|
|
153
|
+
const catchContent = cloneContent(executeContent, {
|
|
154
|
+
source: {
|
|
155
|
+
id: message.content.id,
|
|
156
|
+
type: message.content.type,
|
|
157
|
+
executionId: message.content.executionId,
|
|
158
|
+
},
|
|
159
|
+
error,
|
|
160
|
+
executionId: parent.executionId,
|
|
161
|
+
});
|
|
162
|
+
catchContent.parent = shiftParent(parent);
|
|
163
|
+
|
|
164
|
+
const broker = this.broker;
|
|
165
|
+
broker.publish('event', 'activity.catch', catchContent, {type: 'catch'});
|
|
166
|
+
|
|
167
|
+
return broker.publish('execution', 'execute.completed', cloneContent(executeContent, {
|
|
168
|
+
output: error,
|
|
169
|
+
cancelActivity: true,
|
|
170
|
+
state: 'catch',
|
|
171
|
+
}));
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
proto._onApiMessage = function onApiMessage(routingKey, message) {
|
|
175
|
+
const messageType = message.properties.type;
|
|
176
|
+
|
|
177
|
+
switch (messageType) {
|
|
178
|
+
case 'discard': {
|
|
179
|
+
this[kCompleted] = true;
|
|
180
|
+
this._stop();
|
|
181
|
+
return this.broker.publish('execution', 'execute.discard', cloneContent(this[kExecuteMessage].content));
|
|
108
182
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
broker.cancel(`_onerror-${executionId}`);
|
|
113
|
-
broker.cancel(`_api-${executionId}`);
|
|
114
|
-
broker.purgeQueue(errorQueueName);
|
|
183
|
+
case 'stop': {
|
|
184
|
+
this._stop();
|
|
185
|
+
break;
|
|
115
186
|
}
|
|
116
187
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
message: {...
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return broker.publish('execution', 'execute.completed', {...messageContent, message: referenceMessage});
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
proto._stop = function stop() {
|
|
191
|
+
const broker = this.broker, executionId = this.executionId;
|
|
192
|
+
broker.cancel(`_onthrow-${executionId}`);
|
|
193
|
+
broker.cancel(`_onerror-${executionId}`);
|
|
194
|
+
broker.cancel(`_api-${executionId}`);
|
|
195
|
+
this[kMessageQ].purge();
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
proto._getReferenceInfo = function getReferenceInfo(message) {
|
|
199
|
+
const referenceElement = this[kReferenceElement];
|
|
200
|
+
if (!referenceElement) {
|
|
201
|
+
return {
|
|
202
|
+
message: {...this.reference},
|
|
203
|
+
description: 'anonymous error',
|
|
204
|
+
};
|
|
136
205
|
}
|
|
137
206
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
message: {...reference},
|
|
142
|
-
description: 'anonymous error',
|
|
143
|
-
};
|
|
144
|
-
}
|
|
207
|
+
const result = {
|
|
208
|
+
message: referenceElement.resolve(message),
|
|
209
|
+
};
|
|
145
210
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
};
|
|
211
|
+
result.description = `${result.message.name} <${result.message.id}>`;
|
|
212
|
+
if (result.message.code) result.description += ` code ${result.message.code}`;
|
|
149
213
|
|
|
150
|
-
|
|
151
|
-
|
|
214
|
+
return result;
|
|
215
|
+
};
|
|
152
216
|
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function setupCatch() {
|
|
157
|
-
broker.assertQueue(errorQueueName, {autoDelete: false, durable: true});
|
|
158
|
-
broker.bindQueue(errorQueueName, 'api', '*.throw.#', {durable: true, priority: 300});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
217
|
+
proto._debug = function debug(msg) {
|
|
218
|
+
this.logger.debug(`<${this.executionId} (${this.activity.id})> ${msg}`);
|
|
219
|
+
};
|