bpmn-elements 13.1.1 → 13.2.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/README.md +1 -2
- package/dist/Context.js +36 -2
- package/dist/definition/DefinitionExecution.js +2 -1
- package/dist/getPropertyValue.js +1 -2
- package/dist/index.js +1 -1
- package/package.json +14 -13
- package/src/Api.js +18 -20
- package/src/Context.js +49 -7
- package/src/Environment.js +10 -20
- package/src/EventBroker.js +21 -27
- package/src/MessageFormatter.js +23 -19
- package/src/Tracker.js +4 -4
- package/src/activity/Activity.js +141 -109
- package/src/activity/ActivityExecution.js +38 -29
- package/src/activity/Dummy.js +3 -3
- package/src/activity/Escalation.js +4 -4
- package/src/activity/ExecutionScope.js +4 -4
- package/src/activity/Message.js +5 -5
- package/src/activity/Signal.js +5 -5
- package/src/definition/Definition.js +44 -36
- package/src/definition/DefinitionExecution.js +98 -66
- package/src/error/BpmnError.js +3 -3
- package/src/error/Errors.js +19 -14
- package/src/eventDefinitions/CancelEventDefinition.js +16 -11
- package/src/eventDefinitions/CompensateEventDefinition.js +28 -23
- package/src/eventDefinitions/ConditionalEventDefinition.js +42 -23
- package/src/eventDefinitions/ErrorEventDefinition.js +47 -34
- package/src/eventDefinitions/EscalationEventDefinition.js +21 -20
- package/src/eventDefinitions/EventDefinitionExecution.js +6 -6
- package/src/eventDefinitions/LinkEventDefinition.js +28 -22
- package/src/eventDefinitions/MessageEventDefinition.js +47 -36
- package/src/eventDefinitions/SignalEventDefinition.js +42 -31
- package/src/eventDefinitions/TerminateEventDefinition.js +4 -4
- package/src/eventDefinitions/TimerEventDefinition.js +41 -29
- package/src/events/BoundaryEvent.js +81 -46
- package/src/events/EndEvent.js +2 -2
- package/src/events/IntermediateCatchEvent.js +8 -4
- package/src/events/IntermediateThrowEvent.js +2 -2
- package/src/events/StartEvent.js +29 -18
- package/src/flows/Association.js +11 -11
- package/src/flows/MessageFlow.js +16 -14
- package/src/flows/SequenceFlow.js +22 -20
- package/src/gateways/EventBasedGateway.js +7 -6
- package/src/gateways/ExclusiveGateway.js +4 -4
- package/src/gateways/InclusiveGateway.js +3 -3
- package/src/gateways/ParallelGateway.js +4 -4
- package/src/getPropertyValue.js +3 -6
- package/src/index.js +1 -1
- package/src/io/BpmnIO.js +5 -6
- package/src/io/EnvironmentDataObject.js +2 -3
- package/src/io/EnvironmentDataStore.js +2 -2
- package/src/io/EnvironmentDataStoreReference.js +2 -2
- package/src/io/InputOutputSpecification.js +60 -54
- package/src/io/Properties.js +45 -33
- package/src/iso-duration.js +9 -13
- package/src/messageHelper.js +16 -23
- package/src/process/Lane.js +3 -3
- package/src/process/Process.js +40 -34
- package/src/process/ProcessExecution.js +122 -78
- package/src/tasks/CallActivity.js +109 -57
- package/src/tasks/LoopCharacteristics.js +30 -18
- package/src/tasks/ReceiveTask.js +59 -38
- package/src/tasks/ScriptTask.js +17 -8
- package/src/tasks/ServiceTask.js +16 -9
- package/src/tasks/SignalTask.js +47 -28
- package/src/tasks/StandardLoopCharacteristics.js +3 -3
- package/src/tasks/SubProcess.js +9 -8
- package/src/tasks/Task.js +4 -3
- package/src/tasks/Transaction.js +1 -1
- package/types/index.d.ts +6 -6
- package/types/types.d.ts +39 -35
- package/CHANGELOG.md +0 -455
- package/src/ExtensionsMapper.js +0 -42
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {RunError} from '../error/Errors.js';
|
|
2
|
-
import {cloneContent, cloneMessage, unshiftParent, cloneParent} from '../messageHelper.js';
|
|
1
|
+
import { RunError } from '../error/Errors.js';
|
|
2
|
+
import { cloneContent, cloneMessage, unshiftParent, cloneParent } from '../messageHelper.js';
|
|
3
3
|
|
|
4
4
|
export default function LoopCharacteristics(activity, loopCharacteristics) {
|
|
5
5
|
this.activity = activity;
|
|
6
6
|
this.loopCharacteristics = loopCharacteristics;
|
|
7
|
-
const {type = 'LoopCharacteristics', behaviour = {}} = loopCharacteristics;
|
|
7
|
+
const { type = 'LoopCharacteristics', behaviour = {} } = loopCharacteristics;
|
|
8
8
|
this.type = type;
|
|
9
|
-
const {isSequential = false, collection} = behaviour;
|
|
9
|
+
const { isSequential = false, collection } = behaviour;
|
|
10
10
|
this.isSequential = isSequential;
|
|
11
11
|
this.collection = collection;
|
|
12
12
|
|
|
@@ -36,10 +36,12 @@ export default function LoopCharacteristics(activity, loopCharacteristics) {
|
|
|
36
36
|
|
|
37
37
|
LoopCharacteristics.prototype.execute = function execute(executeMessage) {
|
|
38
38
|
if (!executeMessage) throw new TypeError('LoopCharacteristics execution requires message');
|
|
39
|
-
const chr = this.characteristics = this.characteristics || new Characteristics(this.activity, this.loopCharacteristics, executeMessage);
|
|
39
|
+
const chr = (this.characteristics = this.characteristics || new Characteristics(this.activity, this.loopCharacteristics, executeMessage));
|
|
40
40
|
if (chr.cardinality === 0) return chr.complete();
|
|
41
41
|
|
|
42
|
-
const execution = this.isSequential
|
|
42
|
+
const execution = this.isSequential
|
|
43
|
+
? new SequentialLoopCharacteristics(this.activity, chr)
|
|
44
|
+
: new ParallelLoopCharacteristics(this.activity, chr);
|
|
43
45
|
return execution.execute(executeMessage);
|
|
44
46
|
};
|
|
45
47
|
|
|
@@ -50,7 +52,7 @@ function SequentialLoopCharacteristics(activity, characteristics) {
|
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
SequentialLoopCharacteristics.prototype.execute = function execute(executeMessage) {
|
|
53
|
-
const {routingKey: executeRoutingKey, redelivered: isRedelivered} = executeMessage.fields || {};
|
|
55
|
+
const { routingKey: executeRoutingKey, redelivered: isRedelivered } = executeMessage.fields || {};
|
|
54
56
|
const chr = this.characteristics;
|
|
55
57
|
if (!chr.cardinality && !chr.startCondition && !chr.completionCondition) {
|
|
56
58
|
throw new RunError(`<${this.id}> cardinality, collection, or condition is required in sequential loops`, executeMessage);
|
|
@@ -70,7 +72,7 @@ SequentialLoopCharacteristics.prototype._startNext = function startNext(index, i
|
|
|
70
72
|
const content = chr.next(index);
|
|
71
73
|
if (!content) return;
|
|
72
74
|
|
|
73
|
-
if (chr.isStartConditionMet({content})) {
|
|
75
|
+
if (chr.isStartConditionMet({ content })) {
|
|
74
76
|
chr.debug('start condition met');
|
|
75
77
|
return;
|
|
76
78
|
}
|
|
@@ -86,12 +88,12 @@ SequentialLoopCharacteristics.prototype._startNext = function startNext(index, i
|
|
|
86
88
|
state: 'iteration.next',
|
|
87
89
|
});
|
|
88
90
|
|
|
89
|
-
broker.publish('execution', 'execute.start', {...content, ignoreIfExecuting});
|
|
91
|
+
broker.publish('execution', 'execute.start', { ...content, ignoreIfExecuting });
|
|
90
92
|
return content;
|
|
91
93
|
};
|
|
92
94
|
|
|
93
95
|
SequentialLoopCharacteristics.prototype._onCompleteMessage = function onCompleteMessage(_, message) {
|
|
94
|
-
const {content} = message;
|
|
96
|
+
const { content } = message;
|
|
95
97
|
const chr = this.characteristics;
|
|
96
98
|
const loopOutput = chr.output;
|
|
97
99
|
|
|
@@ -175,7 +177,7 @@ ParallelLoopCharacteristics.prototype._startBatch = function startBatch() {
|
|
|
175
177
|
|
|
176
178
|
ParallelLoopCharacteristics.prototype._onCompleteMessage = function onCompleteMessage(routingKey, message) {
|
|
177
179
|
const chr = this.characteristics;
|
|
178
|
-
const {content} = message;
|
|
180
|
+
const { content } = message;
|
|
179
181
|
if (content.output !== undefined) chr.output[content.index] = content.output;
|
|
180
182
|
|
|
181
183
|
if (routingKey === 'execute.discard') {
|
|
@@ -211,10 +213,10 @@ ParallelLoopCharacteristics.prototype._onCompleteMessage = function onCompleteMe
|
|
|
211
213
|
|
|
212
214
|
function Characteristics(activity, loopCharacteristics, executeMessage) {
|
|
213
215
|
this.activity = activity;
|
|
214
|
-
const behaviour = this.behaviour = loopCharacteristics.behaviour || {};
|
|
216
|
+
const behaviour = (this.behaviour = loopCharacteristics.behaviour || {});
|
|
215
217
|
this.message = executeMessage;
|
|
216
218
|
|
|
217
|
-
const type = this.type = loopCharacteristics.type || 'LoopCharacteristics';
|
|
219
|
+
const type = (this.type = loopCharacteristics.type || 'LoopCharacteristics');
|
|
218
220
|
this.id = activity.id;
|
|
219
221
|
this.broker = activity.broker;
|
|
220
222
|
this.parentExecutionId = executeMessage.content.executionId;
|
|
@@ -234,7 +236,7 @@ function Characteristics(activity, loopCharacteristics, executeMessage) {
|
|
|
234
236
|
this.completionCondition = behaviour.completionCondition;
|
|
235
237
|
}
|
|
236
238
|
|
|
237
|
-
const collection = this.collection = this.getCollection();
|
|
239
|
+
const collection = (this.collection = this.getCollection());
|
|
238
240
|
if (collection) {
|
|
239
241
|
this.elementVariable = behaviour.elementVariable || 'item';
|
|
240
242
|
}
|
|
@@ -285,7 +287,7 @@ Characteristics.prototype.getCardinality = function getCardinality(collection) {
|
|
|
285
287
|
return collectionLen;
|
|
286
288
|
}
|
|
287
289
|
const value = this.activity.environment.resolveExpression(this.loopCardinality, this.message);
|
|
288
|
-
if (value !== undefined && isNaN(value) || value < 0) {
|
|
290
|
+
if ((value !== undefined && isNaN(value)) || value < 0) {
|
|
289
291
|
throw new RunError(`<${this.id}> invalid loop cardinality >${value}<`, this.message);
|
|
290
292
|
}
|
|
291
293
|
if (value === undefined) return collectionLen;
|
|
@@ -305,7 +307,7 @@ Characteristics.prototype.isStartConditionMet = function isStartConditionMet(mes
|
|
|
305
307
|
|
|
306
308
|
Characteristics.prototype.isCompletionConditionMet = function isCompletionConditionMet(message) {
|
|
307
309
|
if (!this.completionCondition) return false;
|
|
308
|
-
return this.activity.environment.resolveExpression(this.completionCondition, cloneMessage(message, {loopOutput: this.output}));
|
|
310
|
+
return this.activity.environment.resolveExpression(this.completionCondition, cloneMessage(message, { loopOutput: this.output }));
|
|
309
311
|
};
|
|
310
312
|
|
|
311
313
|
Characteristics.prototype.complete = function complete(content, allDiscarded) {
|
|
@@ -319,8 +321,18 @@ Characteristics.prototype.complete = function complete(content, allDiscarded) {
|
|
|
319
321
|
};
|
|
320
322
|
|
|
321
323
|
Characteristics.prototype.subscribe = function subscribe(onIterationCompleteMessage) {
|
|
322
|
-
this.broker.subscribeTmp(
|
|
323
|
-
|
|
324
|
+
this.broker.subscribeTmp(
|
|
325
|
+
'api',
|
|
326
|
+
`activity.*.${this.parentExecutionId}`,
|
|
327
|
+
this.onApiMessage,
|
|
328
|
+
{ noAck: true, consumerTag: '_api-multi-instance-tag' },
|
|
329
|
+
{ priority: 400 },
|
|
330
|
+
);
|
|
331
|
+
this.broker.subscribeTmp('execution', 'execute.*', onComplete, {
|
|
332
|
+
noAck: true,
|
|
333
|
+
consumerTag: '_execute-q-multi-instance-tag',
|
|
334
|
+
priority: 300,
|
|
335
|
+
});
|
|
324
336
|
|
|
325
337
|
function onComplete(routingKey, message, ...args) {
|
|
326
338
|
if (!message.content.isMultiInstance) return;
|
package/src/tasks/ReceiveTask.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Activity from '../activity/Activity.js';
|
|
2
|
-
import {cloneContent} from '../messageHelper.js';
|
|
2
|
+
import { cloneContent } from '../messageHelper.js';
|
|
3
3
|
|
|
4
4
|
const kCompleted = Symbol.for('completed');
|
|
5
5
|
const kExecuteMessage = Symbol.for('executeMessage');
|
|
@@ -9,25 +9,26 @@ const kReferenceInfo = Symbol.for('referenceInfo');
|
|
|
9
9
|
export default function ReceiveTask(activityDef, context) {
|
|
10
10
|
const task = new Activity(ReceiveTaskBehaviour, activityDef, context);
|
|
11
11
|
|
|
12
|
-
task.broker.assertQueue('message', {autoDelete: false, durable: true});
|
|
13
|
-
task.broker.bindQueue('message', 'api', '*.message.#', {durable: true});
|
|
12
|
+
task.broker.assertQueue('message', { autoDelete: false, durable: true });
|
|
13
|
+
task.broker.bindQueue('message', 'api', '*.message.#', { durable: true });
|
|
14
14
|
|
|
15
15
|
return task;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export function ReceiveTaskBehaviour(activity) {
|
|
19
|
-
const {id, type, behaviour} = activity;
|
|
19
|
+
const { id, type, behaviour } = activity;
|
|
20
20
|
|
|
21
21
|
this.id = id;
|
|
22
22
|
this.type = type;
|
|
23
23
|
|
|
24
|
-
const reference = this.reference = {
|
|
24
|
+
const reference = (this.reference = {
|
|
25
25
|
name: 'anonymous',
|
|
26
26
|
...behaviour.messageRef,
|
|
27
27
|
referenceType: 'message',
|
|
28
|
-
};
|
|
28
|
+
});
|
|
29
29
|
|
|
30
|
-
this.loopCharacteristics =
|
|
30
|
+
this.loopCharacteristics =
|
|
31
|
+
behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
|
|
31
32
|
this.activity = activity;
|
|
32
33
|
this.broker = activity.broker;
|
|
33
34
|
|
|
@@ -39,7 +40,7 @@ ReceiveTaskBehaviour.prototype.execute = function execute(executeMessage) {
|
|
|
39
40
|
};
|
|
40
41
|
|
|
41
42
|
function ReceiveTaskExecution(parent) {
|
|
42
|
-
const {activity, broker, loopCharacteristics, reference} = parent;
|
|
43
|
+
const { activity, broker, loopCharacteristics, reference } = parent;
|
|
43
44
|
|
|
44
45
|
this.id = activity.id;
|
|
45
46
|
this.logger = activity.logger;
|
|
@@ -55,10 +56,10 @@ ReceiveTaskExecution.prototype.execute = function execute(executeMessage) {
|
|
|
55
56
|
this[kExecuteMessage] = executeMessage;
|
|
56
57
|
|
|
57
58
|
const executeContent = executeMessage.content;
|
|
58
|
-
const {executionId, isRootScope} = executeContent;
|
|
59
|
+
const { executionId, isRootScope } = executeContent;
|
|
59
60
|
this.executionId = executionId;
|
|
60
61
|
|
|
61
|
-
const info = this[kReferenceInfo] = this._getReferenceInfo(executeMessage);
|
|
62
|
+
const info = (this[kReferenceInfo] = this._getReferenceInfo(executeMessage));
|
|
62
63
|
|
|
63
64
|
if (isRootScope) {
|
|
64
65
|
this._setupMessageHandling(executionId);
|
|
@@ -85,16 +86,16 @@ ReceiveTaskExecution.prototype.execute = function execute(executeMessage) {
|
|
|
85
86
|
|
|
86
87
|
this._debug(`expect ${info.description}`);
|
|
87
88
|
|
|
88
|
-
broker.publish('event', 'activity.wait', cloneContent(executeContent, {message: {...info.message}}));
|
|
89
|
+
broker.publish('event', 'activity.wait', cloneContent(executeContent, { message: { ...info.message } }));
|
|
89
90
|
};
|
|
90
91
|
|
|
91
92
|
ReceiveTaskExecution.prototype._onCatchMessage = function onCatchMessage(routingKey, message) {
|
|
92
93
|
const content = message.content;
|
|
93
94
|
|
|
94
|
-
const {id: signalId, executionId: signalExecutionId} = content.message || {};
|
|
95
|
-
const {message: referenceMessage, description} = this[kReferenceInfo];
|
|
95
|
+
const { id: signalId, executionId: signalExecutionId } = content.message || {};
|
|
96
|
+
const { message: referenceMessage, description } = this[kReferenceInfo];
|
|
96
97
|
|
|
97
|
-
if (!referenceMessage.id && signalId || signalExecutionId) {
|
|
98
|
+
if ((!referenceMessage.id && signalId) || signalExecutionId) {
|
|
98
99
|
if (this.loopCharacteristics && signalExecutionId !== this.executionId) return;
|
|
99
100
|
if (signalId !== this.id && signalExecutionId !== this.executionId) return;
|
|
100
101
|
this._debug('caught direct message');
|
|
@@ -103,27 +104,33 @@ ReceiveTaskExecution.prototype._onCatchMessage = function onCatchMessage(routing
|
|
|
103
104
|
this._debug(`caught ${description}`);
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
const {type: messageType, correlationId} = message.properties;
|
|
107
|
+
const { type: messageType, correlationId } = message.properties;
|
|
107
108
|
const broker = this.broker;
|
|
108
109
|
const executeContent = this[kExecuteMessage].content;
|
|
109
110
|
|
|
110
|
-
broker.publish('event', 'activity.consumed', cloneContent(executeContent, {message: {...message.content.message}}), {
|
|
111
|
-
|
|
111
|
+
broker.publish('event', 'activity.consumed', cloneContent(executeContent, { message: { ...message.content.message } }), {
|
|
112
|
+
correlationId,
|
|
113
|
+
type: messageType,
|
|
114
|
+
});
|
|
115
|
+
broker.publish('event', 'activity.catch', cloneContent(executeContent, { message: message.content.message }), {
|
|
116
|
+
type: 'catch',
|
|
117
|
+
correlationId,
|
|
118
|
+
});
|
|
112
119
|
|
|
113
|
-
this._complete(message.content.message, {correlationId});
|
|
120
|
+
this._complete(message.content.message, { correlationId });
|
|
114
121
|
};
|
|
115
122
|
|
|
116
123
|
ReceiveTaskExecution.prototype._onApiMessage = function onApiMessage(routingKey, message) {
|
|
117
|
-
const {type: messageType, correlationId} = message.properties;
|
|
124
|
+
const { type: messageType, correlationId } = message.properties;
|
|
118
125
|
switch (messageType) {
|
|
119
126
|
case 'message':
|
|
120
127
|
case 'signal': {
|
|
121
|
-
return this._complete(message.content.message, {correlationId});
|
|
128
|
+
return this._complete(message.content.message, { correlationId });
|
|
122
129
|
}
|
|
123
130
|
case 'discard': {
|
|
124
131
|
this[kCompleted] = true;
|
|
125
132
|
this._stop();
|
|
126
|
-
return this.broker.publish('execution', 'execute.discard', cloneContent(this[kExecuteMessage].content), {correlationId});
|
|
133
|
+
return this.broker.publish('execution', 'execute.discard', cloneContent(this[kExecuteMessage].content), { correlationId });
|
|
127
134
|
}
|
|
128
135
|
case 'stop': {
|
|
129
136
|
return this._stop();
|
|
@@ -134,34 +141,47 @@ ReceiveTaskExecution.prototype._onApiMessage = function onApiMessage(routingKey,
|
|
|
134
141
|
ReceiveTaskExecution.prototype._complete = function complete(output, options) {
|
|
135
142
|
this[kCompleted] = true;
|
|
136
143
|
this._stop();
|
|
137
|
-
return this.broker.publish('execution', 'execute.completed', cloneContent(this[kExecuteMessage].content, {output}), options);
|
|
144
|
+
return this.broker.publish('execution', 'execute.completed', cloneContent(this[kExecuteMessage].content, { output }), options);
|
|
138
145
|
};
|
|
139
146
|
|
|
140
147
|
ReceiveTaskExecution.prototype._stop = function stop() {
|
|
141
|
-
const broker = this.broker,
|
|
148
|
+
const broker = this.broker,
|
|
149
|
+
executionId = this.executionId;
|
|
142
150
|
broker.cancel(`_onmessage-${executionId}`);
|
|
143
151
|
broker.cancel(`_api-${executionId}`);
|
|
144
152
|
};
|
|
145
153
|
|
|
146
154
|
ReceiveTaskExecution.prototype._setupMessageHandling = function setupMessageHandling(executionId) {
|
|
147
155
|
const broker = this.broker;
|
|
148
|
-
broker.subscribeTmp(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
156
|
+
broker.subscribeTmp(
|
|
157
|
+
'api',
|
|
158
|
+
'#.signal.*',
|
|
159
|
+
this._onDelegateMessage.bind(this),
|
|
160
|
+
{
|
|
161
|
+
noAck: true,
|
|
162
|
+
consumerTag: `_api-delegated-${executionId}`,
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
noAck: true,
|
|
166
|
+
},
|
|
167
|
+
);
|
|
154
168
|
broker.subscribeTmp('api', `activity.stop.${executionId}`, this._onStopApiMessage.bind(this), {
|
|
155
169
|
noAck: true,
|
|
156
170
|
consumerTag: `_api-stop-${executionId}`,
|
|
157
171
|
priority: 400,
|
|
158
172
|
});
|
|
159
|
-
broker.subscribeTmp(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
173
|
+
broker.subscribeTmp(
|
|
174
|
+
'execution',
|
|
175
|
+
'execute.#',
|
|
176
|
+
this._onExecutionComplete.bind(this),
|
|
177
|
+
{
|
|
178
|
+
noAck: true,
|
|
179
|
+
consumerTag: `_execution-complete-${executionId}`,
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
noAck: true,
|
|
183
|
+
},
|
|
184
|
+
);
|
|
165
185
|
};
|
|
166
186
|
|
|
167
187
|
ReceiveTaskExecution.prototype._onDelegateMessage = function onDelegateMessage(_, message) {
|
|
@@ -173,7 +193,7 @@ ReceiveTaskExecution.prototype._onStopApiMessage = function onStopApiMessage() {
|
|
|
173
193
|
this._stopMessageHandling(true);
|
|
174
194
|
};
|
|
175
195
|
|
|
176
|
-
ReceiveTaskExecution.prototype._onExecutionComplete = function onExecutionComplete(routingKey, {content}) {
|
|
196
|
+
ReceiveTaskExecution.prototype._onExecutionComplete = function onExecutionComplete(routingKey, { content }) {
|
|
177
197
|
if (!content.isRootScope) return;
|
|
178
198
|
switch (routingKey) {
|
|
179
199
|
case 'execute.completed':
|
|
@@ -185,7 +205,8 @@ ReceiveTaskExecution.prototype._onExecutionComplete = function onExecutionComple
|
|
|
185
205
|
};
|
|
186
206
|
|
|
187
207
|
ReceiveTaskExecution.prototype._stopMessageHandling = function stop(keepMessageQ) {
|
|
188
|
-
const broker = this.broker,
|
|
208
|
+
const broker = this.broker,
|
|
209
|
+
executionId = this.executionId;
|
|
189
210
|
broker.cancel(`_api-delegated-${executionId}`);
|
|
190
211
|
broker.cancel(`_api-stop-${executionId}`);
|
|
191
212
|
broker.cancel(`_execution-complete-${executionId}`);
|
|
@@ -196,7 +217,7 @@ ReceiveTaskExecution.prototype._getReferenceInfo = function getReferenceInfo(mes
|
|
|
196
217
|
const referenceElement = this.referenceElement;
|
|
197
218
|
if (!referenceElement) {
|
|
198
219
|
return {
|
|
199
|
-
message: {...this.reference},
|
|
220
|
+
message: { ...this.reference },
|
|
200
221
|
description: 'anonymous message',
|
|
201
222
|
};
|
|
202
223
|
}
|
package/src/tasks/ScriptTask.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import Activity from '../activity/Activity.js';
|
|
2
2
|
import ExecutionScope from '../activity/ExecutionScope.js';
|
|
3
3
|
import { ActivityError } from '../error/Errors.js';
|
|
4
|
-
import {cloneContent, cloneMessage} from '../messageHelper.js';
|
|
4
|
+
import { cloneContent, cloneMessage } from '../messageHelper.js';
|
|
5
5
|
|
|
6
6
|
export default function ScriptTask(activityDef, context) {
|
|
7
7
|
return new Activity(ScriptTaskBehaviour, activityDef, context);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export function ScriptTaskBehaviour(activity) {
|
|
11
|
-
const {id, type, behaviour} = activity;
|
|
11
|
+
const { id, type, behaviour } = activity;
|
|
12
12
|
|
|
13
13
|
this.id = id;
|
|
14
14
|
this.type = type;
|
|
15
15
|
this.scriptFormat = behaviour.scriptFormat;
|
|
16
16
|
|
|
17
|
-
this.loopCharacteristics =
|
|
17
|
+
this.loopCharacteristics =
|
|
18
|
+
behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
|
|
18
19
|
this.activity = activity;
|
|
19
|
-
const environment = this.environment = activity.environment;
|
|
20
|
+
const environment = (this.environment = activity.environment);
|
|
20
21
|
|
|
21
22
|
environment.registerScript(activity);
|
|
22
23
|
}
|
|
@@ -28,10 +29,14 @@ ScriptTaskBehaviour.prototype.execute = function execute(executeMessage) {
|
|
|
28
29
|
return loopCharacteristics.execute(executeMessage);
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
const activity = this.activity,
|
|
32
|
+
const activity = this.activity,
|
|
33
|
+
scriptFormat = this.scriptFormat;
|
|
32
34
|
const script = this.environment.getScript(scriptFormat, activity, cloneMessage(executeMessage));
|
|
33
35
|
if (!script) {
|
|
34
|
-
return activity.emitFatal(
|
|
36
|
+
return activity.emitFatal(
|
|
37
|
+
new ActivityError(`Script format ${scriptFormat} is unsupported or was not registered for <${activity.id}>`, executeMessage),
|
|
38
|
+
executeContent,
|
|
39
|
+
);
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
return script.execute(ExecutionScope(activity, executeMessage), scriptCallback);
|
|
@@ -39,8 +44,12 @@ ScriptTaskBehaviour.prototype.execute = function execute(executeMessage) {
|
|
|
39
44
|
function scriptCallback(err, output) {
|
|
40
45
|
if (err) {
|
|
41
46
|
activity.logger.error(`<${executeContent.executionId} (${activity.id})>`, err);
|
|
42
|
-
return activity.broker.publish(
|
|
47
|
+
return activity.broker.publish(
|
|
48
|
+
'execution',
|
|
49
|
+
'execute.error',
|
|
50
|
+
cloneContent(executeContent, { error: new ActivityError(err.message, executeMessage, err) }, { mandatory: true }),
|
|
51
|
+
);
|
|
43
52
|
}
|
|
44
|
-
return activity.broker.publish('execution', 'execute.completed', cloneContent(executeContent, {output}));
|
|
53
|
+
return activity.broker.publish('execution', 'execute.completed', cloneContent(executeContent, { output }));
|
|
45
54
|
}
|
|
46
55
|
};
|
package/src/tasks/ServiceTask.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import Activity from '../activity/Activity.js';
|
|
2
|
-
import {ActivityError} from '../error/Errors.js';
|
|
3
|
-
import {cloneMessage, cloneContent} from '../messageHelper.js';
|
|
2
|
+
import { ActivityError } from '../error/Errors.js';
|
|
3
|
+
import { cloneMessage, cloneContent } from '../messageHelper.js';
|
|
4
4
|
|
|
5
5
|
export default function ServiceTask(activityDef, context) {
|
|
6
6
|
return new Activity(ServiceTaskBehaviour, activityDef, context);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export function ServiceTaskBehaviour(activity) {
|
|
10
|
-
const {id, type, behaviour} = activity;
|
|
10
|
+
const { id, type, behaviour } = activity;
|
|
11
11
|
|
|
12
12
|
this.id = id;
|
|
13
13
|
this.type = type;
|
|
14
|
-
this.loopCharacteristics =
|
|
14
|
+
this.loopCharacteristics =
|
|
15
|
+
behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
|
|
15
16
|
this.activity = activity;
|
|
16
17
|
this.environment = activity.environment;
|
|
17
18
|
this.broker = activity.broker;
|
|
@@ -25,20 +26,26 @@ ServiceTaskBehaviour.prototype.execute = function execute(executeMessage) {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
const executionId = executeContent.executionId;
|
|
28
|
-
const service = this.service = this.getService(executeMessage);
|
|
29
|
+
const service = (this.service = this.getService(executeMessage));
|
|
29
30
|
if (!service) return this.activity.emitFatal(new ActivityError(`<${this.id}> service not defined`, executeMessage), executeContent);
|
|
30
31
|
|
|
31
32
|
const broker = this.broker;
|
|
32
|
-
broker.subscribeTmp('api', `activity.#.${executionId}`, (...args) => this._onApiMessage(executeMessage, ...args), {
|
|
33
|
+
broker.subscribeTmp('api', `activity.#.${executionId}`, (...args) => this._onApiMessage(executeMessage, ...args), {
|
|
34
|
+
consumerTag: `_api-${executionId}`,
|
|
35
|
+
});
|
|
33
36
|
|
|
34
37
|
return service.execute(executeMessage, (err, output) => {
|
|
35
38
|
broker.cancel(`_api-${executionId}`);
|
|
36
39
|
if (err) {
|
|
37
40
|
this.activity.logger.error(`<${executionId} (${this.id})>`, err);
|
|
38
|
-
return broker.publish(
|
|
41
|
+
return broker.publish(
|
|
42
|
+
'execution',
|
|
43
|
+
'execute.error',
|
|
44
|
+
cloneContent(executeContent, { error: new ActivityError(err.message, executeMessage, err) }, { mandatory: true }),
|
|
45
|
+
);
|
|
39
46
|
}
|
|
40
47
|
|
|
41
|
-
return broker.publish('execution', 'execute.completed', cloneContent(executeContent, {output, state: 'complete'}));
|
|
48
|
+
return broker.publish('execution', 'execute.completed', cloneContent(executeContent, { output, state: 'complete' }));
|
|
42
49
|
});
|
|
43
50
|
};
|
|
44
51
|
|
|
@@ -60,7 +67,7 @@ ServiceTaskBehaviour.prototype._onApiMessage = function onApiMessage(executeMess
|
|
|
60
67
|
else if (service.stop) service.stop(message);
|
|
61
68
|
}
|
|
62
69
|
this.activity.logger.debug(`<${executionId} (${this.id})> discarded`);
|
|
63
|
-
return broker.publish('execution', 'execute.discard', cloneContent(executeMessage.content, {state: 'discard'}));
|
|
70
|
+
return broker.publish('execution', 'execute.discard', cloneContent(executeMessage.content, { state: 'discard' }));
|
|
64
71
|
}
|
|
65
72
|
case 'stop': {
|
|
66
73
|
const executionId = executeMessage.content.executionId;
|
package/src/tasks/SignalTask.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import Activity from '../activity/Activity.js';
|
|
2
|
-
import {ActivityError} from '../error/Errors.js';
|
|
3
|
-
import {cloneContent} from '../messageHelper.js';
|
|
2
|
+
import { ActivityError } from '../error/Errors.js';
|
|
3
|
+
import { cloneContent } from '../messageHelper.js';
|
|
4
4
|
|
|
5
5
|
export default function SignalTask(activityDef, context) {
|
|
6
6
|
return new Activity(SignalTaskBehaviour, activityDef, context);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export function SignalTaskBehaviour(activity) {
|
|
10
|
-
const {id, type, behaviour} = activity;
|
|
10
|
+
const { id, type, behaviour } = activity;
|
|
11
11
|
|
|
12
12
|
this.id = id;
|
|
13
13
|
this.type = type;
|
|
14
|
-
this.loopCharacteristics =
|
|
14
|
+
this.loopCharacteristics =
|
|
15
|
+
behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
|
|
15
16
|
this.activity = activity;
|
|
16
17
|
this.broker = activity.broker;
|
|
17
18
|
}
|
|
@@ -34,56 +35,74 @@ SignalTaskBehaviour.prototype.execute = function execute(executeMessage) {
|
|
|
34
35
|
noAck: true,
|
|
35
36
|
consumerTag: `_api-delegated-${executionId}`,
|
|
36
37
|
});
|
|
37
|
-
broker.publish('event', 'activity.wait', cloneContent(executeContent, {state: 'wait'}));
|
|
38
|
+
broker.publish('event', 'activity.wait', cloneContent(executeContent, { state: 'wait' }));
|
|
38
39
|
};
|
|
39
40
|
|
|
40
41
|
SignalTaskBehaviour.prototype._onDelegatedApiMessage = function onDelegatedApiMessage(executeMessage, routingKey, message) {
|
|
41
42
|
if (!message.properties.delegate) return;
|
|
42
43
|
|
|
43
|
-
const {content: delegateContent} = message;
|
|
44
|
+
const { content: delegateContent } = message;
|
|
44
45
|
if (!delegateContent || !delegateContent.message) return;
|
|
45
46
|
|
|
46
47
|
const executeContent = executeMessage.content;
|
|
47
|
-
const {id: signalId, executionId: signalExecutionId} = delegateContent.message;
|
|
48
|
+
const { id: signalId, executionId: signalExecutionId } = delegateContent.message;
|
|
48
49
|
if (this.loopCharacteristics && signalExecutionId !== executeContent.executionId) return;
|
|
49
50
|
if (signalId !== this.id && signalExecutionId !== executeContent.executionId) return;
|
|
50
51
|
|
|
51
|
-
const {type: messageType, correlationId} = message.properties;
|
|
52
|
-
this.broker.publish(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
const { type: messageType, correlationId } = message.properties;
|
|
53
|
+
this.broker.publish(
|
|
54
|
+
'event',
|
|
55
|
+
'activity.consumed',
|
|
56
|
+
cloneContent(executeContent, {
|
|
57
|
+
message: { ...delegateContent.message },
|
|
58
|
+
}),
|
|
59
|
+
{
|
|
60
|
+
correlationId,
|
|
61
|
+
type: messageType,
|
|
62
|
+
},
|
|
63
|
+
);
|
|
58
64
|
|
|
59
65
|
return this._onApiMessage(executeMessage, routingKey, message);
|
|
60
66
|
};
|
|
61
67
|
|
|
62
68
|
SignalTaskBehaviour.prototype._onApiMessage = function onApiMessage(executeMessage, routingKey, message) {
|
|
63
|
-
const {type: messageType, correlationId} = message.properties;
|
|
69
|
+
const { type: messageType, correlationId } = message.properties;
|
|
64
70
|
const executeContent = executeMessage.content;
|
|
65
71
|
switch (messageType) {
|
|
66
72
|
case 'stop':
|
|
67
73
|
return this._stop(executeContent.executionId);
|
|
68
74
|
case 'signal':
|
|
69
75
|
this._stop(executeContent.executionId);
|
|
70
|
-
return this.broker.publish(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
return this.broker.publish(
|
|
77
|
+
'execution',
|
|
78
|
+
'execute.completed',
|
|
79
|
+
cloneContent(executeContent, {
|
|
80
|
+
output: message.content.message,
|
|
81
|
+
state: 'signal',
|
|
82
|
+
}),
|
|
83
|
+
{
|
|
84
|
+
correlationId,
|
|
85
|
+
},
|
|
86
|
+
);
|
|
76
87
|
case 'error':
|
|
77
88
|
this._stop(executeContent.executionId);
|
|
78
|
-
return this.broker.publish(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
return this.broker.publish(
|
|
90
|
+
'execution',
|
|
91
|
+
'execute.error',
|
|
92
|
+
cloneContent(
|
|
93
|
+
executeContent,
|
|
94
|
+
{
|
|
95
|
+
error: new ActivityError(message.content.message, executeMessage, message.content),
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
mandatory: true,
|
|
99
|
+
correlationId,
|
|
100
|
+
},
|
|
101
|
+
),
|
|
102
|
+
);
|
|
84
103
|
case 'discard':
|
|
85
104
|
this._stop(executeContent.executionId);
|
|
86
|
-
return this.broker.publish('execution', 'execute.discard', cloneContent(executeContent), {correlationId});
|
|
105
|
+
return this.broker.publish('execution', 'execute.discard', cloneContent(executeContent), { correlationId });
|
|
87
106
|
}
|
|
88
107
|
};
|
|
89
108
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import LoopCharacteristics from './LoopCharacteristics.js';
|
|
2
2
|
|
|
3
3
|
export default function StandardLoopCharacteristics(activity, loopCharacteristics) {
|
|
4
|
-
let {behaviour} = loopCharacteristics;
|
|
5
|
-
behaviour = {...behaviour, isSequential: true};
|
|
6
|
-
return new LoopCharacteristics(activity, {...loopCharacteristics, behaviour});
|
|
4
|
+
let { behaviour } = loopCharacteristics;
|
|
5
|
+
behaviour = { ...behaviour, isSequential: true };
|
|
6
|
+
return new LoopCharacteristics(activity, { ...loopCharacteristics, behaviour });
|
|
7
7
|
}
|
package/src/tasks/SubProcess.js
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
1
|
import Activity from '../activity/Activity.js';
|
|
2
2
|
import ProcessExecution from '../process/ProcessExecution.js';
|
|
3
|
-
import {cloneContent} from '../messageHelper.js';
|
|
3
|
+
import { cloneContent } from '../messageHelper.js';
|
|
4
4
|
|
|
5
5
|
const kExecutions = Symbol.for('executions');
|
|
6
6
|
const kMessageHandlers = Symbol.for('messageHandlers');
|
|
7
7
|
|
|
8
8
|
export default function SubProcess(activityDef, context) {
|
|
9
9
|
const triggeredByEvent = activityDef.behaviour && activityDef.behaviour.triggeredByEvent;
|
|
10
|
-
const subProcess = new Activity(SubProcessBehaviour, {...activityDef, isSubProcess: true, triggeredByEvent}, context);
|
|
10
|
+
const subProcess = new Activity(SubProcessBehaviour, { ...activityDef, isSubProcess: true, triggeredByEvent }, context);
|
|
11
11
|
|
|
12
12
|
subProcess.getStartActivities = function getStartActivities(filterOptions) {
|
|
13
13
|
return context.getStartActivities(filterOptions, activityDef.id);
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
subProcess.broker.cancel('_api-shake');
|
|
17
|
-
subProcess.broker.subscribeTmp('api', 'activity.shake.*', onShake, {noAck: true, consumerTag: '_api-shake'});
|
|
17
|
+
subProcess.broker.subscribeTmp('api', 'activity.shake.*', onShake, { noAck: true, consumerTag: '_api-shake' });
|
|
18
18
|
|
|
19
19
|
return subProcess;
|
|
20
20
|
|
|
21
21
|
function onShake(_, message) {
|
|
22
|
-
const {startId} = message.content;
|
|
22
|
+
const { startId } = message.content;
|
|
23
23
|
const last = message.content.sequence.pop();
|
|
24
24
|
const sequence = new ProcessExecution(subProcess, context).shake(startId);
|
|
25
|
-
message.content.sequence.push({...last, isSubProcess: true, sequence});
|
|
25
|
+
message.content.sequence.push({ ...last, isSubProcess: true, sequence });
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export function SubProcessBehaviour(activity, context) {
|
|
30
|
-
const {id, type, behaviour} = activity;
|
|
30
|
+
const { id, type, behaviour } = activity;
|
|
31
31
|
this.id = id;
|
|
32
32
|
this.type = type;
|
|
33
|
-
this.loopCharacteristics =
|
|
33
|
+
this.loopCharacteristics =
|
|
34
|
+
behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
|
|
34
35
|
this.activity = activity;
|
|
35
36
|
this.context = context;
|
|
36
37
|
this.environment = activity.environment;
|
|
@@ -173,7 +174,7 @@ SubProcessBehaviour.prototype._onExecutionCompleted = function onExecutionComple
|
|
|
173
174
|
case 'error': {
|
|
174
175
|
broker.cancel(message.fields.consumerTag);
|
|
175
176
|
|
|
176
|
-
const {error} = content;
|
|
177
|
+
const { error } = content;
|
|
177
178
|
this.activity.logger.error(`<${this.id}>`, error);
|
|
178
179
|
|
|
179
180
|
return this._completeExecution('execute.error', content);
|