bpmn-elements 6.0.1 → 8.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/CHANGELOG.md +341 -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 +1105 -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 +16 -16
- 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 +914 -776
- 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
|
@@ -13,169 +13,203 @@ var _messageHelper = require("../messageHelper");
|
|
|
13
13
|
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
15
|
|
|
16
|
+
const kCompleted = Symbol.for('completed');
|
|
17
|
+
const kMessageQ = Symbol.for('messageQ');
|
|
18
|
+
const kExecuteMessage = Symbol.for('executeMessage');
|
|
19
|
+
const kReferenceElement = Symbol.for('referenceElement');
|
|
20
|
+
const kReference = Symbol.for('reference');
|
|
21
|
+
|
|
16
22
|
function EscalationEventDefinition(activity, eventDefinition) {
|
|
17
23
|
const {
|
|
18
24
|
id,
|
|
19
25
|
broker,
|
|
20
26
|
environment,
|
|
21
|
-
isThrowing
|
|
22
|
-
getActivityById
|
|
27
|
+
isThrowing
|
|
23
28
|
} = activity;
|
|
24
29
|
const {
|
|
25
30
|
type,
|
|
26
31
|
behaviour = {}
|
|
27
32
|
} = eventDefinition;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const referenceElement = reference.id && getActivityById(reference.id);
|
|
35
|
-
const escalationId = referenceElement ? referenceElement.id : 'anonymous';
|
|
36
|
-
const escalationQueueName = `escalate-${(0, _shared.brokerSafeId)(id)}-${(0, _shared.brokerSafeId)(escalationId)}-q`;
|
|
37
|
-
if (!isThrowing) setupCatch();
|
|
38
|
-
const source = {
|
|
39
|
-
id,
|
|
40
|
-
type,
|
|
41
|
-
reference: { ...reference,
|
|
42
|
-
referenceType: 'escalate'
|
|
43
|
-
},
|
|
44
|
-
execute: isThrowing ? executeThrow : executeCatch
|
|
33
|
+
this.id = id;
|
|
34
|
+
this.type = type;
|
|
35
|
+
const reference = this.reference = {
|
|
36
|
+
name: 'anonymous',
|
|
37
|
+
...behaviour.escalationRef,
|
|
38
|
+
referenceType: 'escalate'
|
|
45
39
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
} = resolveMessage(executeMessage);
|
|
60
|
-
broker.consume(escalationQueueName, onEscalationApiMessage, {
|
|
61
|
-
noAck: true,
|
|
62
|
-
consumerTag: `_onescalate-${executionId}`
|
|
63
|
-
});
|
|
64
|
-
if (completed) return;
|
|
65
|
-
broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
|
|
66
|
-
noAck: true,
|
|
67
|
-
consumerTag: `_api-${executionId}`
|
|
40
|
+
this.isThrowing = isThrowing;
|
|
41
|
+
this.activity = activity;
|
|
42
|
+
this.broker = broker;
|
|
43
|
+
this.logger = environment.Logger(type.toLowerCase());
|
|
44
|
+
const referenceElement = this[kReferenceElement] = reference.id && activity.getActivityById(reference.id);
|
|
45
|
+
|
|
46
|
+
if (!isThrowing) {
|
|
47
|
+
this[kCompleted] = false;
|
|
48
|
+
const referenceId = referenceElement ? referenceElement.id : 'anonymous';
|
|
49
|
+
const messageQueueName = `${reference.referenceType}-${(0, _shared.brokerSafeId)(id)}-${(0, _shared.brokerSafeId)(referenceId)}-q`;
|
|
50
|
+
this[kMessageQ] = broker.assertQueue(messageQueueName, {
|
|
51
|
+
autoDelete: false,
|
|
52
|
+
durable: true
|
|
68
53
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
executionId: parentExecutionId,
|
|
73
|
-
parent: (0, _messageHelper.shiftParent)(parent),
|
|
74
|
-
escalation: { ...referenceMessage
|
|
75
|
-
}
|
|
54
|
+
broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, {
|
|
55
|
+
durable: true,
|
|
56
|
+
priority: 400
|
|
76
57
|
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const proto = EscalationEventDefinition.prototype;
|
|
62
|
+
Object.defineProperty(proto, 'executionId', {
|
|
63
|
+
get() {
|
|
64
|
+
const message = this[kExecuteMessage];
|
|
65
|
+
return message && message.content.executionId;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
proto.execute = function execute(executeMessage) {
|
|
71
|
+
return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
|
|
72
|
+
};
|
|
77
73
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
74
|
+
proto.executeCatch = function executeCatch(executeMessage) {
|
|
75
|
+
this[kExecuteMessage] = executeMessage;
|
|
76
|
+
this[kCompleted] = false;
|
|
77
|
+
const executeContent = executeMessage.content;
|
|
78
|
+
const {
|
|
79
|
+
executionId,
|
|
80
|
+
parent
|
|
81
|
+
} = executeContent;
|
|
82
|
+
|
|
83
|
+
const info = this[kReference] = this._getReferenceInfo(executeMessage);
|
|
84
|
+
|
|
85
|
+
const broker = this.broker;
|
|
86
|
+
this[kMessageQ].consume(this._onCatchMessage.bind(this), {
|
|
87
|
+
noAck: true,
|
|
88
|
+
consumerTag: `_onescalate-${executionId}`
|
|
89
|
+
});
|
|
90
|
+
if (this[kCompleted]) return;
|
|
91
|
+
broker.subscribeTmp('api', `activity.#.${executionId}`, this._onApiMessage.bind(this), {
|
|
92
|
+
noAck: true,
|
|
93
|
+
consumerTag: `_api-${executionId}`
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
this._debug(`expect ${info.description}`);
|
|
97
|
+
|
|
98
|
+
const waitContent = (0, _messageHelper.cloneContent)(executeContent, {
|
|
99
|
+
executionId: parent.executionId,
|
|
100
|
+
parent: (0, _messageHelper.shiftParent)(parent),
|
|
101
|
+
escalation: { ...info.message
|
|
96
102
|
}
|
|
103
|
+
});
|
|
104
|
+
waitContent.parent = (0, _messageHelper.shiftParent)(parent);
|
|
105
|
+
broker.publish('event', 'activity.wait', waitContent);
|
|
106
|
+
};
|
|
97
107
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
108
|
+
proto.executeThrow = function executeThrow(executeMessage) {
|
|
109
|
+
const executeContent = executeMessage.content;
|
|
110
|
+
const {
|
|
111
|
+
executionId,
|
|
112
|
+
parent
|
|
113
|
+
} = executeContent;
|
|
114
|
+
|
|
115
|
+
const info = this._getReferenceInfo(executeMessage);
|
|
116
|
+
|
|
117
|
+
this.logger.debug(`<${executionId} (${this.activity.id})> escalate ${info.description}`);
|
|
118
|
+
const broker = this.broker;
|
|
119
|
+
const throwContent = (0, _messageHelper.cloneContent)(executeContent, {
|
|
120
|
+
executionId: parent.executionId,
|
|
121
|
+
message: info.message,
|
|
122
|
+
state: 'throw'
|
|
123
|
+
});
|
|
124
|
+
throwContent.parent = (0, _messageHelper.shiftParent)(parent);
|
|
125
|
+
broker.publish('event', 'activity.escalate', throwContent, {
|
|
126
|
+
type: 'escalate',
|
|
127
|
+
delegate: true
|
|
128
|
+
});
|
|
129
|
+
return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeContent));
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
proto._onCatchMessage = function onCatchMessage(routingKey, message) {
|
|
133
|
+
const info = this[kReference];
|
|
134
|
+
if ((0, _getPropertyValue.default)(message, 'content.message.id') !== info.message.id) return;
|
|
135
|
+
const output = message.content.message;
|
|
136
|
+
this[kCompleted] = true;
|
|
137
|
+
|
|
138
|
+
this._stop();
|
|
139
|
+
|
|
140
|
+
this._debug(`caught ${info.description}`);
|
|
141
|
+
|
|
142
|
+
const executeContent = this[kExecuteMessage].content;
|
|
143
|
+
const {
|
|
144
|
+
parent,
|
|
145
|
+
...content
|
|
146
|
+
} = executeContent;
|
|
147
|
+
const catchContent = (0, _messageHelper.cloneContent)(content, {
|
|
148
|
+
message: { ...output
|
|
149
|
+
},
|
|
150
|
+
executionId: parent.executionId
|
|
151
|
+
});
|
|
152
|
+
catchContent.parent = (0, _messageHelper.shiftParent)(parent);
|
|
153
|
+
const broker = this.broker;
|
|
154
|
+
broker.publish('event', 'activity.catch', catchContent, {
|
|
155
|
+
type: 'catch'
|
|
156
|
+
});
|
|
157
|
+
return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeContent, {
|
|
158
|
+
output,
|
|
159
|
+
state: 'catch'
|
|
160
|
+
}));
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
proto._onApiMessage = function onApiMessage(routingKey, message) {
|
|
164
|
+
switch (message.properties.type) {
|
|
165
|
+
case 'escalate':
|
|
166
|
+
{
|
|
167
|
+
return this._onCatchMessage(routingKey, message);
|
|
120
168
|
}
|
|
121
|
-
}
|
|
122
169
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
}
|
|
170
|
+
case 'discard':
|
|
171
|
+
{
|
|
172
|
+
this[kCompleted] = true;
|
|
128
173
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
debug(`<${executionId} (${id})> escalate ${description}`);
|
|
141
|
-
broker.publish('event', 'activity.escalate', { ...(0, _messageHelper.cloneContent)(messageContent),
|
|
142
|
-
executionId: parentExecutionId,
|
|
143
|
-
parent: (0, _messageHelper.shiftParent)(parent),
|
|
144
|
-
message: { ...referenceMessage
|
|
145
|
-
},
|
|
146
|
-
state: 'throw'
|
|
147
|
-
}, {
|
|
148
|
-
type: 'escalate',
|
|
149
|
-
delegate: true
|
|
150
|
-
});
|
|
151
|
-
return broker.publish('execution', 'execute.completed', { ...messageContent
|
|
152
|
-
});
|
|
174
|
+
this._stop();
|
|
175
|
+
|
|
176
|
+
return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[kExecuteMessage].content));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
case 'stop':
|
|
180
|
+
{
|
|
181
|
+
this._stop();
|
|
182
|
+
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
153
185
|
}
|
|
186
|
+
};
|
|
154
187
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
};
|
|
162
|
-
}
|
|
188
|
+
proto._stop = function stop() {
|
|
189
|
+
const broker = this.broker,
|
|
190
|
+
executionId = this.executionId;
|
|
191
|
+
broker.cancel(`_api-${executionId}`);
|
|
192
|
+
broker.cancel(`_onescalate-${executionId}`);
|
|
193
|
+
};
|
|
163
194
|
|
|
164
|
-
|
|
165
|
-
|
|
195
|
+
proto._getReferenceInfo = function getReferenceInfo(message) {
|
|
196
|
+
const referenceElement = this[kReferenceElement];
|
|
197
|
+
|
|
198
|
+
if (!referenceElement) {
|
|
199
|
+
return {
|
|
200
|
+
message: { ...this.reference
|
|
201
|
+
},
|
|
202
|
+
description: 'anonymous escalation'
|
|
166
203
|
};
|
|
167
|
-
result.description = `${result.message.name} <${result.message.id}>`;
|
|
168
|
-
return result;
|
|
169
204
|
}
|
|
170
205
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
206
|
+
const result = {
|
|
207
|
+
message: referenceElement.resolve(message)
|
|
208
|
+
};
|
|
209
|
+
result.description = `${result.message.name} <${result.message.id}>`;
|
|
210
|
+
return result;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
proto._debug = function debug(msg) {
|
|
214
|
+
this.logger.debug(`<${this.executionId} (${this.activity.id})> ${msg}`);
|
|
215
|
+
};
|
|
@@ -7,137 +7,165 @@ exports.default = EventDefinitionExecution;
|
|
|
7
7
|
|
|
8
8
|
var _messageHelper = require("../messageHelper");
|
|
9
9
|
|
|
10
|
+
const kCompleted = Symbol.for('completed');
|
|
11
|
+
const kExecuteMessage = Symbol.for('executeMessage');
|
|
12
|
+
const kStopped = Symbol.for('stopped');
|
|
13
|
+
|
|
10
14
|
function EventDefinitionExecution(activity, eventDefinitions, completedRoutingKey = 'execute.completed') {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
case 'execute.discard':
|
|
105
|
-
{
|
|
106
|
-
if (message.content.isDefinitionScope) {
|
|
107
|
-
logger.debug(`<${message.content.executionId} (${id})> event definition ${message.content.type} discarded, index ${message.content.index}`);
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
stop();
|
|
112
|
-
logger.debug(`<${message.content.executionId} (${id})> event definition parent execution discarded`);
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
15
|
+
this.id = activity.id;
|
|
16
|
+
this.activity = activity;
|
|
17
|
+
this.broker = activity.broker;
|
|
18
|
+
this.eventDefinitions = eventDefinitions;
|
|
19
|
+
this.completedRoutingKey = completedRoutingKey;
|
|
20
|
+
this[kCompleted] = false;
|
|
21
|
+
this[kStopped] = false;
|
|
22
|
+
this[kExecuteMessage] = null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const proto = EventDefinitionExecution.prototype;
|
|
26
|
+
Object.defineProperty(proto, 'completed', {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
|
|
29
|
+
get() {
|
|
30
|
+
return this[kCompleted];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(proto, 'stopped', {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
|
|
37
|
+
get() {
|
|
38
|
+
return this[kStopped];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
proto.execute = function execute(executeMessage) {
|
|
44
|
+
const content = executeMessage.content;
|
|
45
|
+
if (content.isDefinitionScope) return this._executeDefinition(executeMessage);
|
|
46
|
+
if (!content.isRootScope) return;
|
|
47
|
+
const broker = this.broker;
|
|
48
|
+
this[kExecuteMessage] = executeMessage;
|
|
49
|
+
const executionId = content.executionId;
|
|
50
|
+
broker.subscribeTmp('execution', 'execute.#', this._onExecuteMessage.bind(this), {
|
|
51
|
+
noAck: true,
|
|
52
|
+
consumerTag: '_eventdefinition-execution-execute-tag',
|
|
53
|
+
priority: 300
|
|
54
|
+
});
|
|
55
|
+
broker.subscribeTmp('api', `activity.*.${executionId}`, this._onApiMessage.bind(this), {
|
|
56
|
+
noAck: true,
|
|
57
|
+
consumerTag: '_eventdefinition-execution-api-tag',
|
|
58
|
+
priority: 300
|
|
59
|
+
});
|
|
60
|
+
broker.publish('execution', 'execute.update', (0, _messageHelper.cloneContent)(content, {
|
|
61
|
+
preventComplete: true
|
|
62
|
+
}));
|
|
63
|
+
if (executeMessage.fields.redelivered) return;
|
|
64
|
+
const parent = (0, _messageHelper.unshiftParent)(content.parent, content);
|
|
65
|
+
const eventDefinitions = this.eventDefinitions;
|
|
66
|
+
|
|
67
|
+
for (let index = 0; index < eventDefinitions.length; ++index) {
|
|
68
|
+
if (this[kCompleted]) break;
|
|
69
|
+
if (this[kStopped]) break;
|
|
70
|
+
const ed = eventDefinitions[index];
|
|
71
|
+
const edExecutionId = `${executionId}_${index}`;
|
|
72
|
+
|
|
73
|
+
this._debug(executionId, `start event definition ${ed.type}, index ${index}`);
|
|
74
|
+
|
|
75
|
+
const edContent = (0, _messageHelper.cloneContent)(content, {
|
|
76
|
+
isRootScope: undefined,
|
|
77
|
+
type: ed.type,
|
|
78
|
+
executionId: edExecutionId,
|
|
79
|
+
isDefinitionScope: true,
|
|
80
|
+
index
|
|
81
|
+
});
|
|
82
|
+
edContent.parent = (0, _messageHelper.cloneParent)(parent);
|
|
83
|
+
broker.publish('execution', 'execute.start', edContent);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
proto._onApiMessage = function onApiMessage(_, message) {
|
|
88
|
+
const messageType = message.properties.type;
|
|
89
|
+
|
|
90
|
+
switch (messageType) {
|
|
91
|
+
case 'stop':
|
|
92
|
+
case 'discard':
|
|
93
|
+
return this._stop();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
proto._onExecuteMessage = function onExecuteMessage(routingKey, message) {
|
|
98
|
+
switch (routingKey) {
|
|
99
|
+
case 'execute.completed':
|
|
100
|
+
{
|
|
101
|
+
this._stop();
|
|
102
|
+
|
|
103
|
+
if (message.content.isDefinitionScope) return this._complete(message);
|
|
104
|
+
break;
|
|
115
105
|
}
|
|
116
106
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
107
|
+
case 'execute.discard':
|
|
108
|
+
{
|
|
109
|
+
const {
|
|
110
|
+
executionId,
|
|
111
|
+
isDefinitionScope
|
|
112
|
+
} = message.content;
|
|
113
|
+
|
|
114
|
+
if (isDefinitionScope) {
|
|
115
|
+
this._debug(executionId, `event definition ${message.content.type} discarded, index ${message.content.index}`);
|
|
116
|
+
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
this._stop();
|
|
121
|
+
|
|
122
|
+
this._debug(executionId, 'event definition parent execution discarded');
|
|
123
|
+
|
|
124
|
+
break;
|
|
128
125
|
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function executeDefinition() {
|
|
132
|
-
const ed = eventDefinitions[executeContent.index];
|
|
133
|
-
if (!ed) return logger.warn(`<${messageExecutionId} (${id})> found no event definition on index ${executeContent.index}`);
|
|
134
|
-
logger.debug(`<${messageExecutionId} (${id})> execute event definition ${ed.type}, index ${executeContent.index}`);
|
|
135
|
-
ed.execute(executeMessage);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function stop() {
|
|
139
|
-
broker.cancel(executeConsumerTag);
|
|
140
|
-
broker.cancel(apiConsumerTag);
|
|
141
|
-
}
|
|
142
126
|
}
|
|
143
|
-
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
proto._complete = function complete(message) {
|
|
130
|
+
const {
|
|
131
|
+
executionId,
|
|
132
|
+
type,
|
|
133
|
+
index,
|
|
134
|
+
parent
|
|
135
|
+
} = message.content;
|
|
136
|
+
this[kCompleted] = true;
|
|
137
|
+
|
|
138
|
+
this._debug(executionId, `event definition ${type} completed, index ${index}`);
|
|
139
|
+
|
|
140
|
+
const completeContent = (0, _messageHelper.cloneContent)(message.content, {
|
|
141
|
+
executionId: this[kExecuteMessage].content.executionId,
|
|
142
|
+
isRootScope: true
|
|
143
|
+
});
|
|
144
|
+
completeContent.parent = (0, _messageHelper.shiftParent)(parent);
|
|
145
|
+
this.broker.publish('execution', this.completedRoutingKey, completeContent, {
|
|
146
|
+
correlationId: message.properties.correlationId
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
proto._executeDefinition = function executeDefinition(message) {
|
|
151
|
+
const {
|
|
152
|
+
executionId,
|
|
153
|
+
index
|
|
154
|
+
} = message.content;
|
|
155
|
+
const ed = this.eventDefinitions[index];
|
|
156
|
+
if (!ed) return this.activity.logger.warn(`<${executionId} (${this.id})> found no event definition on index ${index}`);
|
|
157
|
+
|
|
158
|
+
this._debug(executionId, `execute event definition ${ed.type}, index ${index}`);
|
|
159
|
+
|
|
160
|
+
ed.execute(message);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
proto._stop = function stop() {
|
|
164
|
+
this[kStopped] = true;
|
|
165
|
+
this.broker.cancel('_eventdefinition-execution-execute-tag');
|
|
166
|
+
this.broker.cancel('_eventdefinition-execution-api-tag');
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
proto._debug = function debug(executionId, msg) {
|
|
170
|
+
this.activity.logger.debug(`<${executionId} (${this.id})> ${msg}`);
|
|
171
|
+
};
|