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,306 +1,352 @@
|
|
|
1
1
|
import {ActivityApi} from '../Api';
|
|
2
2
|
import {cloneContent, cloneMessage} from '../messageHelper';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
getPostponed,
|
|
25
|
-
getState,
|
|
26
|
-
recover,
|
|
27
|
-
stop,
|
|
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
|
+
|
|
10
|
+
export default ActivityExecution;
|
|
11
|
+
|
|
12
|
+
function ActivityExecution(activity, context) {
|
|
13
|
+
this.activity = activity;
|
|
14
|
+
this.context = context;
|
|
15
|
+
this.id = activity.id;
|
|
16
|
+
this.broker = activity.broker;
|
|
17
|
+
this[kPostponed] = [];
|
|
18
|
+
this[kCompleted] = false;
|
|
19
|
+
this[kExecuteQ] = this.broker.assertQueue('execute-q', {durable: true, autoDelete: false});
|
|
20
|
+
|
|
21
|
+
this[kMessageHandlers] = {
|
|
22
|
+
onParentApiMessage: this._onParentApiMessage.bind(this),
|
|
23
|
+
onExecuteMessage: this._onExecuteMessage.bind(this),
|
|
28
24
|
};
|
|
25
|
+
}
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
function getPostponed() {
|
|
33
|
-
let apis = postponed.map((msg) => getApi(msg));
|
|
34
|
-
if (!isSubProcess || !source) return apis;
|
|
35
|
-
apis = apis.concat(source.getPostponed());
|
|
36
|
-
return apis;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function execute(executeMessage) {
|
|
40
|
-
if (!executeMessage) throw new Error('Execution requires message');
|
|
41
|
-
if (!executeMessage.content || !executeMessage.content.executionId) throw new Error('Execution requires execution id');
|
|
42
|
-
|
|
43
|
-
const isRedelivered = executeMessage.fields.redelivered;
|
|
44
|
-
executionId = executeMessage.content.executionId;
|
|
27
|
+
const proto = ActivityExecution.prototype;
|
|
45
28
|
|
|
46
|
-
|
|
47
|
-
|
|
29
|
+
Object.defineProperty(proto, 'completed', {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get() {
|
|
32
|
+
return this[kCompleted];
|
|
33
|
+
},
|
|
34
|
+
});
|
|
48
35
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
36
|
+
proto.execute = function execute(executeMessage) {
|
|
37
|
+
if (!executeMessage) throw new Error('Execution requires message');
|
|
38
|
+
const executionId = executeMessage.content && executeMessage.content.executionId;
|
|
39
|
+
if (!executionId) throw new Error('Execution requires execution id');
|
|
52
40
|
|
|
53
|
-
|
|
41
|
+
this.executionId = executionId;
|
|
42
|
+
const initMessage = this[kExecuteMessage] = cloneMessage(executeMessage, {
|
|
43
|
+
executionId,
|
|
44
|
+
state: 'start',
|
|
45
|
+
isRootScope: true,
|
|
46
|
+
});
|
|
54
47
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
if (executeMessage.fields.redelivered) {
|
|
49
|
+
this[kPostponed].splice(0);
|
|
50
|
+
this._debug('resume execution');
|
|
58
51
|
|
|
59
|
-
|
|
60
|
-
activate();
|
|
61
|
-
source = Behaviour(activity, context);
|
|
62
|
-
broker.publish('execution', 'execute.start', cloneContent(initMessage.content));
|
|
63
|
-
}
|
|
52
|
+
if (!this.source) this.source = new this.activity.Behaviour(this.activity, this.context);
|
|
64
53
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return source.execute(executeMessage);
|
|
54
|
+
this.activate();
|
|
55
|
+
return this.broker.publish('execution', 'execute.resume.execution', cloneContent(initMessage.content), {persistent: false});
|
|
68
56
|
}
|
|
69
57
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
58
|
+
this._debug('execute');
|
|
59
|
+
this.activate();
|
|
60
|
+
this.source = new this.activity.Behaviour(this.activity, this.context);
|
|
61
|
+
this.broker.publish('execution', 'execute.start', cloneContent(initMessage.content));
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
proto.activate = function activate() {
|
|
65
|
+
if (this[kCompleted]) return;
|
|
66
|
+
|
|
67
|
+
const broker = this.broker;
|
|
68
|
+
const batchSize = this.activity.environment.settings.batchSize || 50;
|
|
69
|
+
broker.bindQueue('execute-q', 'execution', 'execute.#', {priority: 100});
|
|
70
|
+
|
|
71
|
+
const {onExecuteMessage, onParentApiMessage} = this[kMessageHandlers];
|
|
72
|
+
this[kExecuteQ].assertConsumer(onExecuteMessage, {
|
|
73
|
+
exclusive: true,
|
|
74
|
+
prefetch: batchSize * 2,
|
|
75
|
+
priority: 100,
|
|
76
|
+
consumerTag: '_activity-execute',
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
if (this[kCompleted]) return this.deactivate();
|
|
80
|
+
|
|
81
|
+
broker.subscribeTmp('api', `activity.*.${this.executionId}`, onParentApiMessage, {
|
|
82
|
+
noAck: true,
|
|
83
|
+
consumerTag: '_activity-api-execution',
|
|
84
|
+
priority: 200,
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
proto.deactivate = function deactivate() {
|
|
89
|
+
const broker = this.broker;
|
|
90
|
+
broker.cancel('_activity-api-execution');
|
|
91
|
+
broker.cancel('_activity-execute');
|
|
92
|
+
broker.unbindQueue('execute-q', 'execution', 'execute.#');
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
proto.discard = function discard() {
|
|
96
|
+
if (this[kCompleted]) return;
|
|
97
|
+
const initMessage = this[kExecuteMessage];
|
|
98
|
+
if (!initMessage) return this.activity.logger.warn(`<${this.id}> is not executing`);
|
|
99
|
+
this.getApi(initMessage).discard();
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
proto.getApi = function getApi(apiMessage) {
|
|
103
|
+
const self = this;
|
|
104
|
+
if (!apiMessage) apiMessage = this[kExecuteMessage];
|
|
105
|
+
|
|
106
|
+
if (self.source.getApi) {
|
|
107
|
+
const sourceApi = self.source.getApi(apiMessage);
|
|
108
|
+
if (sourceApi) return sourceApi;
|
|
74
109
|
}
|
|
75
110
|
|
|
76
|
-
|
|
77
|
-
if (!initMessage) return;
|
|
78
|
-
getApi(initMessage).stop();
|
|
79
|
-
}
|
|
111
|
+
const api = ActivityApi(self.broker, apiMessage);
|
|
80
112
|
|
|
81
|
-
function
|
|
82
|
-
|
|
113
|
+
api.getExecuting = function getExecuting() {
|
|
114
|
+
return self[kPostponed].reduce((result, msg) => {
|
|
115
|
+
if (msg.content.executionId === apiMessage.content.executionId) return result;
|
|
116
|
+
result.push(self.getApi(msg));
|
|
117
|
+
return result;
|
|
118
|
+
}, []);
|
|
119
|
+
};
|
|
83
120
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
121
|
+
return api;
|
|
122
|
+
};
|
|
87
123
|
|
|
88
|
-
|
|
89
|
-
|
|
124
|
+
proto.passthrough = function passthrough(executeMessage) {
|
|
125
|
+
if (!this.source) return this.execute(executeMessage);
|
|
126
|
+
return this._sourceExecute(executeMessage);
|
|
127
|
+
};
|
|
90
128
|
|
|
91
|
-
|
|
92
|
-
|
|
129
|
+
proto.getPostponed = function getPostponed() {
|
|
130
|
+
let apis = this[kPostponed].map((msg) => this.getApi(msg));
|
|
131
|
+
if (!this.activity.isSubProcess || !this.source) return apis;
|
|
132
|
+
apis = apis.concat(this.source.getPostponed());
|
|
133
|
+
return apis;
|
|
134
|
+
};
|
|
93
135
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
136
|
+
proto.getState = function getState() {
|
|
137
|
+
const result = {completed: this[kCompleted]};
|
|
138
|
+
const source = this.source;
|
|
98
139
|
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function activate() {
|
|
103
|
-
if (completed) return;
|
|
140
|
+
if (!source || !source.getState) return result;
|
|
141
|
+
return {...result, ...source.getState()};
|
|
142
|
+
};
|
|
104
143
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (completed) return deactivate();
|
|
144
|
+
proto.recover = function recover(state) {
|
|
145
|
+
this[kPostponed].splice(0);
|
|
108
146
|
|
|
109
|
-
|
|
110
|
-
|
|
147
|
+
if (!state) return this;
|
|
148
|
+
if ('completed' in state) this[kCompleted] = state.completed;
|
|
111
149
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
broker.unbindQueue(executeQ.name, 'execution', 'execute.#');
|
|
150
|
+
const source = this.source = new this.activity.Behaviour(this.activity, this.context);
|
|
151
|
+
if (source.recover) {
|
|
152
|
+
source.recover(state);
|
|
116
153
|
}
|
|
117
154
|
|
|
118
|
-
|
|
119
|
-
|
|
155
|
+
return this;
|
|
156
|
+
};
|
|
120
157
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
onStop(message);
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
158
|
+
proto.stop = function stop() {
|
|
159
|
+
const executeMessage = this[kExecuteMessage];
|
|
160
|
+
if (!executeMessage) return;
|
|
161
|
+
this.getApi(executeMessage).stop();
|
|
162
|
+
};
|
|
130
163
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
api.stop();
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
broker.cancel('_activity-execute');
|
|
141
|
-
broker.cancel('_activity-api-execution');
|
|
164
|
+
proto._sourceExecute = function sourceExecute(executeMessage) {
|
|
165
|
+
try {
|
|
166
|
+
return this.source.execute(executeMessage);
|
|
167
|
+
} catch (error) {
|
|
168
|
+
return this.broker.publish('execution', 'execute.error', cloneContent(executeMessage.content, {error}));
|
|
142
169
|
}
|
|
170
|
+
};
|
|
143
171
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const {isRootScope, ignoreIfExecuting, keep, executionId: cexid, error} = content;
|
|
148
|
-
const {persistent, correlationId} = properties;
|
|
172
|
+
proto._onExecuteMessage = function onExecuteMessage(routingKey, message) {
|
|
173
|
+
const {fields, content, properties} = message;
|
|
174
|
+
const isRedelivered = fields.redelivered;
|
|
149
175
|
|
|
150
|
-
|
|
176
|
+
if (isRedelivered && properties.persistent === false) return message.ack();
|
|
151
177
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return broker.publish('execution', routingKey, getExecuteMessage().content);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
executionCompleted();
|
|
169
|
-
break;
|
|
170
|
-
}
|
|
171
|
-
case 'execute.start': {
|
|
172
|
-
if (!stateChangeMessage()) return;
|
|
173
|
-
return source.execute(getExecuteMessage());
|
|
178
|
+
switch (routingKey) {
|
|
179
|
+
case 'execute.resume.execution': {
|
|
180
|
+
if (!this[kPostponed].length) return this.broker.publish('execution', 'execute.start', cloneContent(this[kExecuteMessage].content));
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
case 'execute.error':
|
|
184
|
+
case 'execute.discard':
|
|
185
|
+
return this._onExecutionDiscarded(message);
|
|
186
|
+
case 'execute.cancel':
|
|
187
|
+
case 'execute.completed': {
|
|
188
|
+
if (isRedelivered) {
|
|
189
|
+
message.ack();
|
|
190
|
+
return this.broker.publish('execution', routingKey, getExecuteMessage(message).content);
|
|
174
191
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
192
|
+
|
|
193
|
+
return this._onExecutionCompleted(message);
|
|
194
|
+
}
|
|
195
|
+
case 'execute.start': {
|
|
196
|
+
if (!this._onStateChangeMessage(message)) return;
|
|
197
|
+
return this._sourceExecute(getExecuteMessage(message));
|
|
198
|
+
}
|
|
199
|
+
case 'execute.outbound.take': {
|
|
200
|
+
if (isRedelivered) {
|
|
201
|
+
message.ack();
|
|
181
202
|
break;
|
|
182
203
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
if (isRedelivered) {
|
|
186
|
-
return source.execute(getExecuteMessage());
|
|
187
|
-
}
|
|
188
|
-
}
|
|
204
|
+
this.broker.publish('execution', 'execution.outbound.take', cloneContent(content), {type: 'outbound'});
|
|
205
|
+
break;
|
|
189
206
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if (idx > -1) {
|
|
195
|
-
if (ignoreIfExecuting) {
|
|
196
|
-
message.ack();
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
previousMsg = postponed.splice(idx, 1, message)[0];
|
|
201
|
-
previousMsg.ack();
|
|
202
|
-
|
|
203
|
-
return true;
|
|
207
|
+
default: {
|
|
208
|
+
if (!this._onStateChangeMessage(message)) return;
|
|
209
|
+
if (isRedelivered) {
|
|
210
|
+
return this._sourceExecute(getExecuteMessage(message));
|
|
204
211
|
}
|
|
205
|
-
|
|
206
|
-
postponed.push(message);
|
|
207
|
-
return true;
|
|
208
212
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
proto._onStateChangeMessage = function onStateChangeMessage(message) {
|
|
217
|
+
const {ignoreIfExecuting, executionId} = message.content;
|
|
218
|
+
const postponed = this[kPostponed];
|
|
219
|
+
const idx = postponed.findIndex((msg) => msg.content.executionId === executionId);
|
|
220
|
+
let previousMsg;
|
|
221
|
+
if (idx > -1) {
|
|
222
|
+
if (ignoreIfExecuting) {
|
|
223
|
+
message.ack();
|
|
224
|
+
return false;
|
|
214
225
|
}
|
|
215
226
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (!postponedMsg) return;
|
|
219
|
-
|
|
220
|
-
if (!isRootScope) {
|
|
221
|
-
logger.debug(`<${cexid} (${id})> completed sub execution`);
|
|
222
|
-
if (!keep) message.ack();
|
|
223
|
-
if (postponed.length === 1 && postponed[0].content.isRootScope && !postponed[0].content.preventComplete) {
|
|
224
|
-
return broker.publish('execution', 'execute.completed', cloneContent(postponed[0].content));
|
|
225
|
-
}
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
logger.debug(`<${cexid} (${id})> completed execution`);
|
|
230
|
-
completed = true;
|
|
227
|
+
previousMsg = postponed.splice(idx, 1, message)[0];
|
|
228
|
+
previousMsg.ack();
|
|
231
229
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
deactivate();
|
|
235
|
-
|
|
236
|
-
const subApis = getPostponed();
|
|
237
|
-
postponed.splice(0);
|
|
238
|
-
subApis.forEach((api) => api.discard());
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
239
232
|
|
|
240
|
-
|
|
233
|
+
postponed.push(message);
|
|
234
|
+
return true;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
proto._onExecutionCompleted = function onExecutionCompleted(message) {
|
|
238
|
+
const postponedMsg = this._ackPostponed(message);
|
|
239
|
+
if (!postponedMsg) return;
|
|
240
|
+
const postponed = this[kPostponed];
|
|
241
|
+
|
|
242
|
+
const {executionId, keep, isRootScope} = message.content;
|
|
243
|
+
if (!isRootScope) {
|
|
244
|
+
this._debug('completed sub execution');
|
|
245
|
+
if (!keep) message.ack();
|
|
246
|
+
if (postponed.length === 1 && postponed[0].content.isRootScope && !postponed[0].content.preventComplete) {
|
|
247
|
+
return this.broker.publish('execution', 'execute.completed', cloneContent(postponed[0].content));
|
|
241
248
|
}
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
242
251
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
if (!isRootScope && !postponedMsg) return;
|
|
252
|
+
this._debug('completed execution', executionId);
|
|
253
|
+
this[kCompleted] = true;
|
|
246
254
|
|
|
247
|
-
|
|
248
|
-
message.ack();
|
|
249
|
-
if (postponed.length === 1 && postponed[0].content.isRootScope) {
|
|
250
|
-
return broker.publish('execution', 'execute.discard', {...postponed[0].content}, {correlationId});
|
|
251
|
-
}
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
255
|
+
message.ack(true);
|
|
254
256
|
|
|
255
|
-
|
|
257
|
+
this.deactivate();
|
|
256
258
|
|
|
257
|
-
|
|
259
|
+
const subApis = this.getPostponed();
|
|
260
|
+
postponed.splice(0);
|
|
261
|
+
for (const api of subApis) api.discard();
|
|
258
262
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
subApis.forEach((api) => api.discard());
|
|
263
|
+
this._publishExecutionCompleted('completed', {...postponedMsg.content, ...message.content}, message.properties.correlationId);
|
|
264
|
+
};
|
|
262
265
|
|
|
263
|
-
|
|
264
|
-
|
|
266
|
+
proto._onExecutionDiscarded = function onExecutionDiscarded(message) {
|
|
267
|
+
const postponedMsg = this._ackPostponed(message);
|
|
268
|
+
const {isRootScope, error} = message.content;
|
|
269
|
+
if (!isRootScope && !postponedMsg) return;
|
|
265
270
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}, {type: completionType, correlationId});
|
|
271
|
+
const postponed = this[kPostponed];
|
|
272
|
+
const correlationId = message.properties.correlationId;
|
|
273
|
+
if (!error && !isRootScope) {
|
|
274
|
+
message.ack();
|
|
275
|
+
if (postponed.length === 1 && postponed[0].content.isRootScope) {
|
|
276
|
+
return this.broker.publish('execution', 'execute.discard', postponed[0].content, {correlationId});
|
|
273
277
|
}
|
|
278
|
+
return;
|
|
274
279
|
}
|
|
275
280
|
|
|
276
|
-
|
|
277
|
-
const {executionId: eid} = completeMessage.content;
|
|
278
|
-
|
|
279
|
-
const idx = postponed.findIndex(({content}) => content.executionId === eid);
|
|
280
|
-
if (idx === -1) return;
|
|
281
|
-
const [msg] = postponed.splice(idx, 1);
|
|
282
|
-
msg.ack();
|
|
283
|
-
return msg;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
function getApi(apiMessage) {
|
|
287
|
-
if (!apiMessage) apiMessage = initMessage;
|
|
281
|
+
message.ack(true);
|
|
288
282
|
|
|
289
|
-
|
|
290
|
-
const sourceApi = source.getApi(apiMessage);
|
|
291
|
-
if (sourceApi) return sourceApi;
|
|
292
|
-
}
|
|
283
|
+
this.deactivate();
|
|
293
284
|
|
|
294
|
-
|
|
285
|
+
const subApis = this.getPostponed();
|
|
286
|
+
postponed.splice(0);
|
|
287
|
+
for (const api of subApis) api.discard();
|
|
295
288
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
result.push(getApi(msg));
|
|
300
|
-
return result;
|
|
301
|
-
}, []);
|
|
302
|
-
};
|
|
289
|
+
if (error) {
|
|
290
|
+
return this._publishExecutionCompleted('error', cloneContent(message.content, {error}), correlationId);
|
|
291
|
+
}
|
|
303
292
|
|
|
304
|
-
|
|
293
|
+
this._publishExecutionCompleted('discard', message.content, correlationId);
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
proto._publishExecutionCompleted = function publishExecutionCompleted(completionType, completeContent, correlationId) {
|
|
297
|
+
this[kCompleted] = true;
|
|
298
|
+
|
|
299
|
+
this.broker.publish('execution', `execution.${completionType}`, {
|
|
300
|
+
...completeContent,
|
|
301
|
+
state: completionType,
|
|
302
|
+
}, {type: completionType, correlationId});
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
proto._ackPostponed = function ackPostponed(completeMessage) {
|
|
306
|
+
const {executionId: eid} = completeMessage.content;
|
|
307
|
+
|
|
308
|
+
const postponed = this[kPostponed];
|
|
309
|
+
const idx = postponed.findIndex(({content: c}) => c.executionId === eid);
|
|
310
|
+
if (idx === -1) return;
|
|
311
|
+
const [msg] = postponed.splice(idx, 1);
|
|
312
|
+
msg.ack();
|
|
313
|
+
return msg;
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
proto._onParentApiMessage = function onParentApiMessage(routingKey, message) {
|
|
317
|
+
switch (message.properties.type) {
|
|
318
|
+
case 'error':
|
|
319
|
+
return this[kExecuteQ].queueMessage({routingKey: 'execute.error'}, {error: message.content.error});
|
|
320
|
+
case 'discard':
|
|
321
|
+
return this[kExecuteQ].queueMessage({routingKey: 'execute.discard'}, cloneContent(this[kExecuteMessage].content));
|
|
322
|
+
case 'stop': {
|
|
323
|
+
return this._onStop(message);
|
|
324
|
+
}
|
|
305
325
|
}
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
proto._onStop = function onStop(message) {
|
|
329
|
+
const stoppedId = message && message.content && message.content.executionId;
|
|
330
|
+
const running = this.getPostponed();
|
|
331
|
+
for (const api of running) {
|
|
332
|
+
if (stoppedId !== api.content.executionId) {
|
|
333
|
+
api.stop();
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
this.broker.cancel('_activity-execute');
|
|
338
|
+
this.broker.cancel('_activity-api-execution');
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
proto._debug = function debug(logMessage, executionId) {
|
|
342
|
+
executionId = executionId || this.executionId;
|
|
343
|
+
this.activity.logger.debug(`<${executionId} (${this.id})> ${logMessage}`);
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
function getExecuteMessage(message) {
|
|
347
|
+
const result = cloneMessage(message, {
|
|
348
|
+
...(message.fields.redelivered ? {isRecovered: true} : undefined),
|
|
349
|
+
ignoreIfExecuting: undefined,
|
|
350
|
+
});
|
|
351
|
+
return result;
|
|
306
352
|
}
|
package/src/activity/Dummy.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {cloneParent} from '../messageHelper';
|
|
2
2
|
|
|
3
3
|
export default function DummyActivity(activityDef) {
|
|
4
|
-
const {id, type = 'dummy', name, parent
|
|
4
|
+
const {id, type = 'dummy', name, parent, behaviour} = activityDef;
|
|
5
5
|
return {
|
|
6
6
|
id,
|
|
7
7
|
type,
|
|
8
8
|
name,
|
|
9
9
|
behaviour: {...behaviour},
|
|
10
|
-
parent: cloneParent(
|
|
10
|
+
parent: cloneParent(parent),
|
|
11
11
|
placeholder: true,
|
|
12
12
|
};
|
|
13
13
|
}
|