bpmn-elements 5.1.3 → 7.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 +322 -0
- package/README.md +9 -3
- package/dist/index.js +71 -39
- package/dist/src/Api.js +77 -76
- package/dist/src/Context.js +169 -164
- package/dist/src/Environment.js +90 -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/Timers.js +4 -6
- package/dist/src/activity/Activity.js +1108 -901
- 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 +722 -409
- 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 -101
- package/dist/src/flows/MessageFlow.js +86 -103
- package/dist/src/flows/SequenceFlow.js +172 -184
- 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 +31 -0
- package/dist/src/io/EnvironmentDataObject.js +33 -29
- package/dist/src/io/EnvironmentDataStore.js +52 -0
- package/dist/src/io/EnvironmentDataStoreReference.js +52 -0
- package/dist/src/io/InputOutputSpecification.js +177 -168
- package/dist/src/io/Properties.js +252 -0
- package/dist/src/messageHelper.js +1 -1
- package/dist/src/process/Process.js +433 -359
- package/dist/src/process/ProcessExecution.js +744 -645
- package/dist/src/shared.js +3 -6
- 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 +195 -175
- package/dist/src/tasks/Task.js +17 -19
- package/index.js +8 -0
- package/package.json +16 -15
- package/src/Api.js +65 -59
- package/src/Context.js +142 -132
- package/src/Environment.js +88 -100
- package/src/EventBroker.js +67 -68
- package/src/ExtensionsMapper.js +2 -2
- package/src/MessageFormatter.js +132 -74
- package/src/Timers.js +4 -4
- package/src/activity/Activity.js +916 -757
- package/src/activity/ActivityExecution.js +293 -247
- package/src/activity/Dummy.js +2 -2
- package/src/definition/Definition.js +436 -401
- package/src/definition/DefinitionExecution.js +603 -343
- package/src/error/Errors.js +11 -6
- package/src/eventDefinitions/CancelEventDefinition.js +164 -121
- package/src/eventDefinitions/CompensateEventDefinition.js +158 -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 -113
- package/src/flows/MessageFlow.js +81 -97
- package/src/flows/SequenceFlow.js +145 -163
- 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 -0
- package/src/io/EnvironmentDataObject.js +29 -18
- package/src/io/EnvironmentDataStore.js +33 -0
- package/src/io/EnvironmentDataStoreReference.js +33 -0
- package/src/io/InputOutputSpecification.js +154 -157
- package/src/io/Properties.js +199 -0
- package/src/process/Process.js +374 -333
- package/src/process/ProcessExecution.js +606 -554
- package/src/shared.js +1 -5
- 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
|
@@ -3,376 +3,421 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = void 0;
|
|
7
7
|
|
|
8
8
|
var _Api = require("../Api");
|
|
9
9
|
|
|
10
10
|
var _messageHelper = require("../messageHelper");
|
|
11
11
|
|
|
12
|
+
const completedSymbol = Symbol.for('completed');
|
|
13
|
+
const executeQSymbol = Symbol.for('executeQ');
|
|
14
|
+
const executeMessageSymbol = Symbol.for('executeMessage');
|
|
15
|
+
const messageHandlersSymbol = Symbol.for('messageHandlers');
|
|
16
|
+
const postponedSymbol = Symbol.for('postponed');
|
|
17
|
+
var _default = ActivityExecution;
|
|
18
|
+
exports.default = _default;
|
|
19
|
+
|
|
12
20
|
function ActivityExecution(activity, context) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} = activity;
|
|
21
|
-
const {
|
|
22
|
-
batchSize = 50
|
|
23
|
-
} = environment.settings;
|
|
24
|
-
const postponed = [];
|
|
25
|
-
let source,
|
|
26
|
-
initMessage,
|
|
27
|
-
completed = false,
|
|
28
|
-
executionId;
|
|
29
|
-
const executeQ = broker.assertQueue('execute-q', {
|
|
21
|
+
this.activity = activity;
|
|
22
|
+
this.context = context;
|
|
23
|
+
this.id = activity.id;
|
|
24
|
+
this.broker = activity.broker;
|
|
25
|
+
this[postponedSymbol] = [];
|
|
26
|
+
this[completedSymbol] = false;
|
|
27
|
+
this[executeQSymbol] = this.broker.assertQueue('execute-q', {
|
|
30
28
|
durable: true,
|
|
31
29
|
autoDelete: false
|
|
32
30
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
get source() {
|
|
39
|
-
return source;
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
discard,
|
|
43
|
-
execute,
|
|
44
|
-
passthrough,
|
|
45
|
-
getApi,
|
|
46
|
-
getPostponed,
|
|
47
|
-
getState,
|
|
48
|
-
recover,
|
|
49
|
-
stop
|
|
31
|
+
this[messageHandlersSymbol] = {
|
|
32
|
+
onParentApiMessage: this._onParentApiMessage.bind(this),
|
|
33
|
+
onExecuteMessage: this._onExecuteMessage.bind(this)
|
|
50
34
|
};
|
|
51
|
-
|
|
35
|
+
}
|
|
52
36
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
37
|
+
const proto = ActivityExecution.prototype;
|
|
38
|
+
Object.defineProperty(proto, 'completed', {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
|
|
41
|
+
get() {
|
|
42
|
+
return this[completedSymbol];
|
|
58
43
|
}
|
|
59
44
|
|
|
60
|
-
|
|
61
|
-
if (!executeMessage) throw new Error('Execution requires message');
|
|
62
|
-
if (!executeMessage.content || !executeMessage.content.executionId) throw new Error('Execution requires execution id');
|
|
63
|
-
const isRedelivered = executeMessage.fields.redelivered;
|
|
64
|
-
executionId = executeMessage.content.executionId;
|
|
65
|
-
initMessage = (0, _messageHelper.cloneMessage)(executeMessage);
|
|
66
|
-
initMessage.content = { ...initMessage.content,
|
|
67
|
-
executionId,
|
|
68
|
-
state: 'start',
|
|
69
|
-
isRootScope: true
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
if (isRedelivered) {
|
|
73
|
-
postponed.splice(0);
|
|
74
|
-
logger.debug(`<${executionId} (${id})> resume execution`);
|
|
75
|
-
if (!source) source = Behaviour(activity, context);
|
|
76
|
-
activate();
|
|
77
|
-
return broker.publish('execution', 'execute.resume.execution', (0, _messageHelper.cloneContent)(initMessage.content), {
|
|
78
|
-
persistent: false
|
|
79
|
-
});
|
|
80
|
-
}
|
|
45
|
+
});
|
|
81
46
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
47
|
+
proto.execute = function execute(executeMessage) {
|
|
48
|
+
if (!executeMessage) throw new Error('Execution requires message');
|
|
49
|
+
const executionId = executeMessage.content && executeMessage.content.executionId;
|
|
50
|
+
if (!executionId) throw new Error('Execution requires execution id');
|
|
51
|
+
this.executionId = executionId;
|
|
52
|
+
const initMessage = this[executeMessageSymbol] = (0, _messageHelper.cloneMessage)(executeMessage, {
|
|
53
|
+
executionId,
|
|
54
|
+
state: 'start',
|
|
55
|
+
isRootScope: true
|
|
56
|
+
});
|
|
87
57
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return source.execute(executeMessage);
|
|
91
|
-
}
|
|
58
|
+
if (executeMessage.fields.redelivered) {
|
|
59
|
+
this[postponedSymbol].splice(0);
|
|
92
60
|
|
|
93
|
-
|
|
94
|
-
if (completed) return;
|
|
95
|
-
if (!initMessage) return logger.warn(`<${id}> is not executing`);
|
|
96
|
-
getApi(initMessage).discard();
|
|
97
|
-
}
|
|
61
|
+
this._debug('resume execution');
|
|
98
62
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
63
|
+
if (!this.source) this.source = new this.activity.Behaviour(this.activity, this.context);
|
|
64
|
+
this.activate();
|
|
65
|
+
return this.broker.publish('execution', 'execute.resume.execution', (0, _messageHelper.cloneContent)(initMessage.content), {
|
|
66
|
+
persistent: false
|
|
67
|
+
});
|
|
102
68
|
}
|
|
103
69
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
70
|
+
this._debug('execute');
|
|
71
|
+
|
|
72
|
+
this.activate();
|
|
73
|
+
this.source = new this.activity.Behaviour(this.activity, this.context);
|
|
74
|
+
this.broker.publish('execution', 'execute.start', (0, _messageHelper.cloneContent)(initMessage.content));
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
proto.activate = function activate() {
|
|
78
|
+
if (this[completedSymbol]) return;
|
|
79
|
+
const broker = this.broker;
|
|
80
|
+
const batchSize = this.activity.environment.settings.batchSize || 50;
|
|
81
|
+
broker.bindQueue('execute-q', 'execution', 'execute.#', {
|
|
82
|
+
priority: 100
|
|
83
|
+
});
|
|
84
|
+
const {
|
|
85
|
+
onExecuteMessage,
|
|
86
|
+
onParentApiMessage
|
|
87
|
+
} = this[messageHandlersSymbol];
|
|
88
|
+
this[executeQSymbol].assertConsumer(onExecuteMessage, {
|
|
89
|
+
exclusive: true,
|
|
90
|
+
prefetch: batchSize * 2,
|
|
91
|
+
priority: 100,
|
|
92
|
+
consumerTag: '_activity-execute'
|
|
93
|
+
});
|
|
94
|
+
if (this[completedSymbol]) return this.deactivate();
|
|
95
|
+
broker.subscribeTmp('api', `activity.*.${this.executionId}`, onParentApiMessage, {
|
|
96
|
+
noAck: true,
|
|
97
|
+
consumerTag: '_activity-api-execution',
|
|
98
|
+
priority: 200
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
proto.deactivate = function deactivate() {
|
|
103
|
+
const broker = this.broker;
|
|
104
|
+
broker.cancel('_activity-api-execution');
|
|
105
|
+
broker.cancel('_activity-execute');
|
|
106
|
+
broker.unbindQueue('execute-q', 'execution', 'execute.#');
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
proto.discard = function discard() {
|
|
110
|
+
if (this[completedSymbol]) return;
|
|
111
|
+
const initMessage = this[executeMessageSymbol];
|
|
112
|
+
if (!initMessage) return this.activity.logger.warn(`<${this.id}> is not executing`);
|
|
113
|
+
this.getApi(initMessage).discard();
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
proto.getApi = function getApi(apiMessage) {
|
|
117
|
+
const self = this;
|
|
118
|
+
if (!apiMessage) apiMessage = this[executeMessageSymbol];
|
|
119
|
+
|
|
120
|
+
if (self.source.getApi) {
|
|
121
|
+
const sourceApi = self.source.getApi(apiMessage);
|
|
122
|
+
if (sourceApi) return sourceApi;
|
|
112
123
|
}
|
|
113
124
|
|
|
114
|
-
|
|
115
|
-
postponed.splice(0);
|
|
116
|
-
if (!state) return executionApi;
|
|
117
|
-
if ('completed' in state) completed = state.completed;
|
|
118
|
-
source = Behaviour(activity, context);
|
|
125
|
+
const api = (0, _Api.ActivityApi)(self.broker, apiMessage);
|
|
119
126
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
127
|
+
api.getExecuting = function getExecuting() {
|
|
128
|
+
return self[postponedSymbol].reduce((result, msg) => {
|
|
129
|
+
if (msg.content.executionId === apiMessage.content.executionId) return result;
|
|
130
|
+
result.push(self.getApi(msg));
|
|
131
|
+
return result;
|
|
132
|
+
}, []);
|
|
133
|
+
};
|
|
123
134
|
|
|
124
|
-
|
|
125
|
-
|
|
135
|
+
return api;
|
|
136
|
+
};
|
|
126
137
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
});
|
|
132
|
-
executeQ.assertConsumer(onExecuteMessage, {
|
|
133
|
-
exclusive: true,
|
|
134
|
-
prefetch: batchSize * 2,
|
|
135
|
-
priority: 100,
|
|
136
|
-
consumerTag: '_activity-execute'
|
|
137
|
-
});
|
|
138
|
-
if (completed) return deactivate();
|
|
139
|
-
broker.subscribeTmp('api', `activity.*.${executionId}`, onParentApiMessage, {
|
|
140
|
-
noAck: true,
|
|
141
|
-
consumerTag: '_activity-api-execution',
|
|
142
|
-
priority: 200
|
|
143
|
-
});
|
|
144
|
-
}
|
|
138
|
+
proto.passthrough = function passthrough(executeMessage) {
|
|
139
|
+
if (!this.source) return this.execute(executeMessage);
|
|
140
|
+
return this._sourceExecute(executeMessage);
|
|
141
|
+
};
|
|
145
142
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
143
|
+
proto.getPostponed = function getPostponed() {
|
|
144
|
+
let apis = this[postponedSymbol].map(msg => this.getApi(msg));
|
|
145
|
+
if (!this.activity.isSubProcess || !this.source) return apis;
|
|
146
|
+
apis = apis.concat(this.source.getPostponed());
|
|
147
|
+
return apis;
|
|
148
|
+
};
|
|
151
149
|
|
|
152
|
-
|
|
153
|
-
|
|
150
|
+
proto.getState = function getState() {
|
|
151
|
+
const result = {
|
|
152
|
+
completed: this[completedSymbol]
|
|
153
|
+
};
|
|
154
|
+
const source = this.source;
|
|
155
|
+
if (!source || !source.getState) return result;
|
|
156
|
+
return { ...result,
|
|
157
|
+
...source.getState()
|
|
158
|
+
};
|
|
159
|
+
};
|
|
154
160
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
break;
|
|
161
|
+
proto.recover = function recover(state) {
|
|
162
|
+
this[postponedSymbol].splice(0);
|
|
163
|
+
if (!state) return this;
|
|
164
|
+
if ('completed' in state) this[completedSymbol] = state.completed;
|
|
165
|
+
const source = this.source = new this.activity.Behaviour(this.activity, this.context);
|
|
161
166
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
167
|
+
if (source.recover) {
|
|
168
|
+
source.recover(state);
|
|
166
169
|
}
|
|
167
170
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
broker.cancel('_activity-execute');
|
|
177
|
-
broker.cancel('_activity-api-execution');
|
|
178
|
-
}
|
|
171
|
+
return this;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
proto.stop = function stop() {
|
|
175
|
+
const executeMessage = this[executeMessageSymbol];
|
|
176
|
+
if (!executeMessage) return;
|
|
177
|
+
this.getApi(executeMessage).stop();
|
|
178
|
+
};
|
|
179
179
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
} = message;
|
|
186
|
-
const isRedelivered = fields.redelivered;
|
|
187
|
-
const {
|
|
188
|
-
isRootScope,
|
|
189
|
-
ignoreIfExecuting,
|
|
190
|
-
keep,
|
|
191
|
-
executionId: cexid,
|
|
180
|
+
proto._sourceExecute = function sourceExecute(executeMessage) {
|
|
181
|
+
try {
|
|
182
|
+
return this.source.execute(executeMessage);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
return this.broker.publish('execution', 'execute.error', (0, _messageHelper.cloneContent)(executeMessage.content, {
|
|
192
185
|
error
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
correlationId
|
|
197
|
-
} = properties;
|
|
198
|
-
if (isRedelivered && persistent === false) return message.ack();
|
|
199
|
-
|
|
200
|
-
switch (routingKey) {
|
|
201
|
-
case 'execute.resume.execution':
|
|
202
|
-
{
|
|
203
|
-
if (!postponed.length) return broker.publish('execution', 'execute.start', (0, _messageHelper.cloneContent)(initMessage.content));
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
186
|
+
}));
|
|
187
|
+
}
|
|
188
|
+
};
|
|
206
189
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
190
|
+
proto._onExecuteMessage = function onExecuteMessage(routingKey, message) {
|
|
191
|
+
const {
|
|
192
|
+
fields,
|
|
193
|
+
content,
|
|
194
|
+
properties
|
|
195
|
+
} = message;
|
|
196
|
+
const isRedelivered = fields.redelivered;
|
|
197
|
+
if (isRedelivered && properties.persistent === false) return message.ack();
|
|
198
|
+
|
|
199
|
+
switch (routingKey) {
|
|
200
|
+
case 'execute.resume.execution':
|
|
201
|
+
{
|
|
202
|
+
if (!this[postponedSymbol].length) return this.broker.publish('execution', 'execute.start', (0, _messageHelper.cloneContent)(this[executeMessageSymbol].content));
|
|
210
203
|
break;
|
|
204
|
+
}
|
|
211
205
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (isRedelivered) {
|
|
216
|
-
message.ack();
|
|
217
|
-
return broker.publish('execution', routingKey, getExecuteMessage().content);
|
|
218
|
-
}
|
|
206
|
+
case 'execute.error':
|
|
207
|
+
case 'execute.discard':
|
|
208
|
+
return this._onExecutionDiscarded(message);
|
|
219
209
|
|
|
220
|
-
|
|
221
|
-
|
|
210
|
+
case 'execute.cancel':
|
|
211
|
+
case 'execute.completed':
|
|
212
|
+
{
|
|
213
|
+
if (isRedelivered) {
|
|
214
|
+
message.ack();
|
|
215
|
+
return this.broker.publish('execution', routingKey, getExecuteMessage(message).content);
|
|
222
216
|
}
|
|
223
217
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
if (!stateChangeMessage()) return;
|
|
227
|
-
return source.execute(getExecuteMessage());
|
|
228
|
-
}
|
|
218
|
+
return this._onExecutionCompleted(message);
|
|
219
|
+
}
|
|
229
220
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
221
|
+
case 'execute.start':
|
|
222
|
+
{
|
|
223
|
+
if (!this._onStateChangeMessage(message)) return;
|
|
224
|
+
return this._sourceExecute(getExecuteMessage(message));
|
|
225
|
+
}
|
|
236
226
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
227
|
+
case 'execute.outbound.take':
|
|
228
|
+
{
|
|
229
|
+
if (isRedelivered) {
|
|
230
|
+
message.ack();
|
|
240
231
|
break;
|
|
241
232
|
}
|
|
242
233
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
234
|
+
this.broker.publish('execution', 'execution.outbound.take', (0, _messageHelper.cloneContent)(content), {
|
|
235
|
+
type: 'outbound'
|
|
236
|
+
});
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
default:
|
|
241
|
+
{
|
|
242
|
+
if (!this._onStateChangeMessage(message)) return;
|
|
246
243
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
244
|
+
if (isRedelivered) {
|
|
245
|
+
return this._sourceExecute(getExecuteMessage(message));
|
|
250
246
|
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
proto._onStateChangeMessage = function onStateChangeMessage(message) {
|
|
252
|
+
const {
|
|
253
|
+
ignoreIfExecuting,
|
|
254
|
+
executionId
|
|
255
|
+
} = message.content;
|
|
256
|
+
const postponed = this[postponedSymbol];
|
|
257
|
+
const idx = postponed.findIndex(msg => msg.content.executionId === executionId);
|
|
258
|
+
let previousMsg;
|
|
259
|
+
|
|
260
|
+
if (idx > -1) {
|
|
261
|
+
if (ignoreIfExecuting) {
|
|
262
|
+
message.ack();
|
|
263
|
+
return false;
|
|
251
264
|
}
|
|
252
265
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
266
|
+
previousMsg = postponed.splice(idx, 1, message)[0];
|
|
267
|
+
previousMsg.ack();
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
256
270
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
271
|
+
postponed.push(message);
|
|
272
|
+
return true;
|
|
273
|
+
};
|
|
262
274
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
return true;
|
|
266
|
-
}
|
|
275
|
+
proto._onExecutionCompleted = function onExecutionCompleted(message) {
|
|
276
|
+
const postponedMsg = this._ackPostponed(message);
|
|
267
277
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
278
|
+
if (!postponedMsg) return;
|
|
279
|
+
const postponed = this[postponedSymbol];
|
|
280
|
+
const {
|
|
281
|
+
executionId,
|
|
282
|
+
keep,
|
|
283
|
+
isRootScope
|
|
284
|
+
} = message.content;
|
|
271
285
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
return
|
|
286
|
+
if (!isRootScope) {
|
|
287
|
+
this._debug('completed sub execution');
|
|
288
|
+
|
|
289
|
+
if (!keep) message.ack();
|
|
290
|
+
|
|
291
|
+
if (postponed.length === 1 && postponed[0].content.isRootScope && !postponed[0].content.preventComplete) {
|
|
292
|
+
return this.broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(postponed[0].content));
|
|
279
293
|
}
|
|
280
294
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
if (!postponedMsg) return;
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
284
297
|
|
|
285
|
-
|
|
286
|
-
logger.debug(`<${cexid} (${id})> completed sub execution`);
|
|
287
|
-
if (!keep) message.ack();
|
|
298
|
+
this._debug('completed execution', executionId);
|
|
288
299
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
300
|
+
this[completedSymbol] = true;
|
|
301
|
+
message.ack(true);
|
|
302
|
+
this.deactivate();
|
|
303
|
+
const subApis = this.getPostponed();
|
|
304
|
+
postponed.splice(0);
|
|
292
305
|
|
|
293
|
-
|
|
294
|
-
}
|
|
306
|
+
for (const api of subApis) api.discard();
|
|
295
307
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
308
|
+
this._publishExecutionCompleted('completed', { ...postponedMsg.content,
|
|
309
|
+
...message.content
|
|
310
|
+
}, message.properties.correlationId);
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
proto._onExecutionDiscarded = function onExecutionDiscarded(message) {
|
|
314
|
+
const postponedMsg = this._ackPostponed(message);
|
|
315
|
+
|
|
316
|
+
const {
|
|
317
|
+
isRootScope,
|
|
318
|
+
error
|
|
319
|
+
} = message.content;
|
|
320
|
+
if (!isRootScope && !postponedMsg) return;
|
|
321
|
+
const postponed = this[postponedSymbol];
|
|
322
|
+
const correlationId = message.properties.correlationId;
|
|
323
|
+
|
|
324
|
+
if (!error && !isRootScope) {
|
|
325
|
+
message.ack();
|
|
326
|
+
|
|
327
|
+
if (postponed.length === 1 && postponed[0].content.isRootScope) {
|
|
328
|
+
return this.broker.publish('execution', 'execute.discard', postponed[0].content, {
|
|
329
|
+
correlationId
|
|
305
330
|
});
|
|
306
331
|
}
|
|
307
332
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
if (!isRootScope && !postponedMsg) return;
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
311
335
|
|
|
312
|
-
|
|
313
|
-
|
|
336
|
+
message.ack(true);
|
|
337
|
+
this.deactivate();
|
|
338
|
+
const subApis = this.getPostponed();
|
|
339
|
+
postponed.splice(0);
|
|
314
340
|
|
|
315
|
-
|
|
316
|
-
return broker.publish('execution', 'execute.discard', { ...postponed[0].content
|
|
317
|
-
}, {
|
|
318
|
-
correlationId
|
|
319
|
-
});
|
|
320
|
-
}
|
|
341
|
+
for (const api of subApis) api.discard();
|
|
321
342
|
|
|
322
|
-
|
|
323
|
-
|
|
343
|
+
if (error) {
|
|
344
|
+
return this._publishExecutionCompleted('error', (0, _messageHelper.cloneContent)(message.content, {
|
|
345
|
+
error
|
|
346
|
+
}), correlationId);
|
|
347
|
+
}
|
|
324
348
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
const subApis = getPostponed();
|
|
328
|
-
postponed.splice(0);
|
|
329
|
-
subApis.forEach(api => api.discard());
|
|
330
|
-
publishExecutionCompleted(error ? 'error' : 'discard', { ...content
|
|
331
|
-
});
|
|
332
|
-
}
|
|
349
|
+
this._publishExecutionCompleted('discard', message.content, correlationId);
|
|
350
|
+
};
|
|
333
351
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
352
|
+
proto._publishExecutionCompleted = function publishExecutionCompleted(completionType, completeContent, correlationId) {
|
|
353
|
+
this[completedSymbol] = true;
|
|
354
|
+
this.broker.publish('execution', `execution.${completionType}`, { ...completeContent,
|
|
355
|
+
state: completionType
|
|
356
|
+
}, {
|
|
357
|
+
type: completionType,
|
|
358
|
+
correlationId
|
|
359
|
+
});
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
proto._ackPostponed = function ackPostponed(completeMessage) {
|
|
363
|
+
const {
|
|
364
|
+
executionId: eid
|
|
365
|
+
} = completeMessage.content;
|
|
366
|
+
const postponed = this[postponedSymbol];
|
|
367
|
+
const idx = postponed.findIndex(({
|
|
368
|
+
content: c
|
|
369
|
+
}) => c.executionId === eid);
|
|
370
|
+
if (idx === -1) return;
|
|
371
|
+
const [msg] = postponed.splice(idx, 1);
|
|
372
|
+
msg.ack();
|
|
373
|
+
return msg;
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
proto._onParentApiMessage = function onParentApiMessage(routingKey, message) {
|
|
377
|
+
switch (message.properties.type) {
|
|
378
|
+
case 'error':
|
|
379
|
+
return this[executeQSymbol].queueMessage({
|
|
380
|
+
routingKey: 'execute.error'
|
|
338
381
|
}, {
|
|
339
|
-
|
|
340
|
-
correlationId
|
|
382
|
+
error: message.content.error
|
|
341
383
|
});
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
384
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
msg.ack();
|
|
355
|
-
return msg;
|
|
385
|
+
case 'discard':
|
|
386
|
+
return this[executeQSymbol].queueMessage({
|
|
387
|
+
routingKey: 'execute.discard'
|
|
388
|
+
}, (0, _messageHelper.cloneContent)(this[executeMessageSymbol].content));
|
|
389
|
+
|
|
390
|
+
case 'stop':
|
|
391
|
+
{
|
|
392
|
+
return this._onStop(message);
|
|
393
|
+
}
|
|
356
394
|
}
|
|
395
|
+
};
|
|
357
396
|
|
|
358
|
-
|
|
359
|
-
|
|
397
|
+
proto._onStop = function onStop(message) {
|
|
398
|
+
const stoppedId = message && message.content && message.content.executionId;
|
|
399
|
+
const running = this.getPostponed();
|
|
360
400
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
401
|
+
for (const api of running) {
|
|
402
|
+
if (stoppedId !== api.content.executionId) {
|
|
403
|
+
api.stop();
|
|
364
404
|
}
|
|
405
|
+
}
|
|
365
406
|
|
|
366
|
-
|
|
407
|
+
this.broker.cancel('_activity-execute');
|
|
408
|
+
this.broker.cancel('_activity-api-execution');
|
|
409
|
+
};
|
|
367
410
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
return result;
|
|
373
|
-
}, []);
|
|
374
|
-
};
|
|
411
|
+
proto._debug = function debug(logMessage, executionId) {
|
|
412
|
+
executionId = executionId || this.executionId;
|
|
413
|
+
this.activity.logger.debug(`<${executionId} (${this.id})> ${logMessage}`);
|
|
414
|
+
};
|
|
375
415
|
|
|
376
|
-
|
|
377
|
-
|
|
416
|
+
function getExecuteMessage(message) {
|
|
417
|
+
const result = (0, _messageHelper.cloneMessage)(message, { ...(message.fields.redelivered ? {
|
|
418
|
+
isRecovered: true
|
|
419
|
+
} : undefined),
|
|
420
|
+
ignoreIfExecuting: undefined
|
|
421
|
+
});
|
|
422
|
+
return result;
|
|
378
423
|
}
|