bpmn-elements 6.0.1 → 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 +3 -0
- package/dist/index.js +52 -44
- package/dist/src/Api.js +77 -76
- package/dist/src/Context.js +169 -175
- 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/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 +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 -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 +433 -359
- package/dist/src/process/ProcessExecution.js +744 -645
- 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 +195 -175
- package/dist/src/tasks/Task.js +17 -19
- package/index.js +2 -0
- package/package.json +13 -13
- package/src/Api.js +65 -59
- package/src/Context.js +138 -141
- 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/activity/Activity.js +915 -775
- 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 -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 +16 -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 +374 -333
- package/src/process/ProcessExecution.js +606 -554
- 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
package/src/tasks/ReceiveTask.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import Activity from '../activity/Activity';
|
|
2
2
|
import {cloneContent} from '../messageHelper';
|
|
3
3
|
|
|
4
|
+
const completedSymbol = Symbol.for('completed');
|
|
5
|
+
const executeMessageSymbol = Symbol.for('executeMessage');
|
|
6
|
+
const referenceElementSymbol = Symbol.for('referenceElement');
|
|
7
|
+
const referenceInfoSymbol = Symbol.for('referenceInfo');
|
|
8
|
+
|
|
4
9
|
export default function ReceiveTask(activityDef, context) {
|
|
5
|
-
const task = Activity(ReceiveTaskBehaviour, activityDef, context);
|
|
10
|
+
const task = new Activity(ReceiveTaskBehaviour, activityDef, context);
|
|
6
11
|
|
|
7
12
|
task.broker.assertQueue('message', {autoDelete: false, durable: true});
|
|
8
13
|
task.broker.bindQueue('message', 'api', '*.message.#', {durable: true});
|
|
@@ -11,140 +16,202 @@ export default function ReceiveTask(activityDef, context) {
|
|
|
11
16
|
}
|
|
12
17
|
|
|
13
18
|
export function ReceiveTaskBehaviour(activity) {
|
|
14
|
-
const {id, type,
|
|
15
|
-
const reference = behaviour.messageRef || {name: 'anonymous'};
|
|
19
|
+
const {id, type, behaviour} = activity;
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
this.id = id;
|
|
22
|
+
this.type = type;
|
|
19
23
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
execute,
|
|
24
|
+
const reference = this.reference = {
|
|
25
|
+
name: 'anonymous',
|
|
26
|
+
...behaviour.messageRef,
|
|
27
|
+
referenceType: 'message',
|
|
25
28
|
};
|
|
26
29
|
|
|
27
|
-
|
|
30
|
+
this.loopCharacteristics = behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
|
|
31
|
+
this.activity = activity;
|
|
32
|
+
this.broker = activity.broker;
|
|
28
33
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const {executionId} = content;
|
|
34
|
+
this[referenceElementSymbol] = reference.id && activity.getActivityById(reference.id);
|
|
35
|
+
}
|
|
32
36
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
+
ReceiveTaskBehaviour.prototype.execute = function execute(executeMessage) {
|
|
38
|
+
return new ReceiveTaskExecution(this).execute(executeMessage);
|
|
39
|
+
};
|
|
37
40
|
|
|
38
|
-
|
|
41
|
+
function ReceiveTaskExecution(parent) {
|
|
42
|
+
const {activity, broker, loopCharacteristics, reference} = parent;
|
|
39
43
|
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
this.id = activity.id;
|
|
45
|
+
this.logger = activity.logger;
|
|
46
|
+
this.reference = reference;
|
|
47
|
+
this.broker = broker;
|
|
48
|
+
this.loopCharacteristics = loopCharacteristics;
|
|
49
|
+
this.referenceElement = parent[referenceElementSymbol];
|
|
42
50
|
|
|
43
|
-
|
|
51
|
+
this[completedSymbol] = false;
|
|
52
|
+
}
|
|
44
53
|
|
|
45
|
-
|
|
54
|
+
const proto = ReceiveTaskExecution.prototype;
|
|
46
55
|
|
|
47
|
-
|
|
56
|
+
proto.execute = function execute(executeMessage) {
|
|
57
|
+
this[executeMessageSymbol] = executeMessage;
|
|
48
58
|
|
|
49
|
-
|
|
59
|
+
const executeContent = executeMessage.content;
|
|
60
|
+
const {executionId, isRootScope} = executeContent;
|
|
61
|
+
this.executionId = executionId;
|
|
50
62
|
|
|
51
|
-
|
|
52
|
-
const {content: delegateContent} = message;
|
|
63
|
+
const info = this[referenceInfoSymbol] = this._getReferenceInfo(executeMessage);
|
|
53
64
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (signalId !== id && signalExecutionId !== executionId) return;
|
|
58
|
-
logger.debug(`<${executionId} (${id})> caught direct message`);
|
|
59
|
-
} else if (referenceMessage.id !== signalId) return;
|
|
60
|
-
else {
|
|
61
|
-
logger.debug(`<${executionId} (${id})> caught ${description}`);
|
|
62
|
-
}
|
|
65
|
+
if (isRootScope) {
|
|
66
|
+
this._setupMessageHandling(executionId);
|
|
67
|
+
}
|
|
63
68
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
const loopCharacteristics = this.loopCharacteristics;
|
|
70
|
+
if (loopCharacteristics && executeMessage.content.isRootScope) {
|
|
71
|
+
return loopCharacteristics.execute(executeMessage);
|
|
72
|
+
}
|
|
67
73
|
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
const broker = this.broker;
|
|
75
|
+
broker.consume('message', this._onCatchMessage.bind(this), {
|
|
76
|
+
noAck: true,
|
|
77
|
+
consumerTag: `_onmessage-${executionId}`,
|
|
78
|
+
});
|
|
70
79
|
|
|
71
|
-
|
|
72
|
-
const {type: messageType, correlationId} = message.properties;
|
|
73
|
-
switch (messageType) {
|
|
74
|
-
case 'message':
|
|
75
|
-
case 'signal': {
|
|
76
|
-
return complete(message.content.message, {correlationId});
|
|
77
|
-
}
|
|
78
|
-
case 'discard': {
|
|
79
|
-
completed = true;
|
|
80
|
-
stop();
|
|
81
|
-
return broker.publish('execution', 'execute.discard', cloneContent(content), {correlationId});
|
|
82
|
-
}
|
|
83
|
-
case 'stop': {
|
|
84
|
-
return stop();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
80
|
+
if (this[completedSymbol]) return;
|
|
88
81
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
82
|
+
broker.subscribeTmp('api', `activity.#.${executionId}`, this._onApiMessage.bind(this), {
|
|
83
|
+
noAck: true,
|
|
84
|
+
consumerTag: `_api-${executionId}`,
|
|
85
|
+
priority: 400,
|
|
86
|
+
});
|
|
94
87
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
88
|
+
this._debug(`expect ${info.description}`);
|
|
89
|
+
|
|
90
|
+
broker.publish('event', 'activity.wait', cloneContent(executeContent, {message: {...info.message}}));
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
proto._onCatchMessage = function onCatchMessage(routingKey, message) {
|
|
94
|
+
const content = message.content;
|
|
95
|
+
|
|
96
|
+
const {id: signalId, executionId: signalExecutionId} = content.message || {};
|
|
97
|
+
const {message: referenceMessage, description} = this[referenceInfoSymbol];
|
|
98
|
+
|
|
99
|
+
if (!referenceMessage.id && signalId || signalExecutionId) {
|
|
100
|
+
if (this.loopCharacteristics && signalExecutionId !== this.executionId) return;
|
|
101
|
+
if (signalId !== this.id && signalExecutionId !== this.executionId) return;
|
|
102
|
+
this._debug('caught direct message');
|
|
103
|
+
} else if (referenceMessage.id !== signalId) return;
|
|
104
|
+
else {
|
|
105
|
+
this._debug(`caught ${description}`);
|
|
99
106
|
}
|
|
100
107
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
broker.subscribeTmp('execution', 'execute.#', onComplete, {noAck: true, consumerTag: `_execution-complete-${executionId}`}, {noAck: true});
|
|
108
|
+
const {type: messageType, correlationId} = message.properties;
|
|
109
|
+
const broker = this.broker;
|
|
110
|
+
const executeContent = this[executeMessageSymbol].content;
|
|
105
111
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
broker.sendToQueue('message', message.content, message.properties);
|
|
109
|
-
}
|
|
112
|
+
broker.publish('event', 'activity.consumed', cloneContent(executeContent, {message: {...message.content.message}}), {correlationId, type: messageType});
|
|
113
|
+
broker.publish('event', 'activity.catch', cloneContent(executeContent, {message: message.content.message}), {type: 'catch', correlationId});
|
|
110
114
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
115
|
+
this._complete(message.content.message, {correlationId});
|
|
116
|
+
};
|
|
114
117
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
stop();
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
118
|
+
proto._onApiMessage = function onApiMessage(routingKey, message) {
|
|
119
|
+
const {type: messageType, correlationId} = message.properties;
|
|
120
|
+
switch (messageType) {
|
|
121
|
+
case 'message':
|
|
122
|
+
case 'signal': {
|
|
123
|
+
return this._complete(message.content.message, {correlationId});
|
|
124
124
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
broker.
|
|
129
|
-
broker.cancel(`_execution-complete-${executionId}`);
|
|
130
|
-
if (!keepMessageQ) broker.purgeQueue('message');
|
|
125
|
+
case 'discard': {
|
|
126
|
+
this[completedSymbol] = true;
|
|
127
|
+
this._stop();
|
|
128
|
+
return this.broker.publish('execution', 'execute.discard', cloneContent(this[executeMessageSymbol].content), {correlationId});
|
|
131
129
|
}
|
|
130
|
+
case 'stop': {
|
|
131
|
+
return this._stop();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
proto._complete = function complete(output, options) {
|
|
137
|
+
this[completedSymbol] = true;
|
|
138
|
+
this._stop();
|
|
139
|
+
return this.broker.publish('execution', 'execute.completed', cloneContent(this[executeMessageSymbol].content, {output}), options);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
proto._stop = function stop() {
|
|
143
|
+
const broker = this.broker, executionId = this.executionId;
|
|
144
|
+
broker.cancel(`_onmessage-${executionId}`);
|
|
145
|
+
broker.cancel(`_api-${executionId}`);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
proto._setupMessageHandling = function setupMessageHandling(executionId) {
|
|
149
|
+
const broker = this.broker;
|
|
150
|
+
broker.subscribeTmp('api', '#.signal.*', this._onDelegateMessage.bind(this), {
|
|
151
|
+
noAck: true,
|
|
152
|
+
consumerTag: `_api-delegated-${executionId}`,
|
|
153
|
+
}, {
|
|
154
|
+
noAck: true,
|
|
155
|
+
});
|
|
156
|
+
broker.subscribeTmp('api', `activity.stop.${executionId}`, this._onStopApiMessage.bind(this), {
|
|
157
|
+
noAck: true,
|
|
158
|
+
consumerTag: `_api-stop-${executionId}`,
|
|
159
|
+
priority: 400,
|
|
160
|
+
});
|
|
161
|
+
broker.subscribeTmp('execution', 'execute.#', this._onExecutionComplete.bind(this), {
|
|
162
|
+
noAck: true,
|
|
163
|
+
consumerTag: `_execution-complete-${executionId}`,
|
|
164
|
+
}, {
|
|
165
|
+
noAck: true,
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
proto._onDelegateMessage = function onDelegateMessage(_, message) {
|
|
170
|
+
if (!message.properties.delegate) return;
|
|
171
|
+
this.broker.sendToQueue('message', message.content, message.properties);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
proto._onStopApiMessage = function onStopApiMessage() {
|
|
175
|
+
this._stopMessageHandling(true);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
proto._onExecutionComplete = function onExecutionComplete(routingKey, {content}) {
|
|
179
|
+
if (!content.isRootScope) return;
|
|
180
|
+
switch (routingKey) {
|
|
181
|
+
case 'execute.completed':
|
|
182
|
+
case 'execute.error':
|
|
183
|
+
case 'execute.discard':
|
|
184
|
+
this._stopMessageHandling();
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
proto._stopMessageHandling = function stop(keepMessageQ) {
|
|
190
|
+
const broker = this.broker, executionId = this.executionId;
|
|
191
|
+
broker.cancel(`_api-delegated-${executionId}`);
|
|
192
|
+
broker.cancel(`_api-stop-${executionId}`);
|
|
193
|
+
broker.cancel(`_execution-complete-${executionId}`);
|
|
194
|
+
if (!keepMessageQ) broker.purgeQueue('message');
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
proto._getReferenceInfo = function getReferenceInfo(message) {
|
|
198
|
+
const referenceElement = this.referenceElement;
|
|
199
|
+
if (!referenceElement) {
|
|
200
|
+
return {
|
|
201
|
+
message: {...this.reference},
|
|
202
|
+
description: 'anonymous message',
|
|
203
|
+
};
|
|
132
204
|
}
|
|
133
205
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
message: {...reference},
|
|
138
|
-
description: 'anonymous message',
|
|
139
|
-
};
|
|
140
|
-
}
|
|
206
|
+
const result = {
|
|
207
|
+
message: referenceElement.resolve(message),
|
|
208
|
+
};
|
|
141
209
|
|
|
142
|
-
|
|
143
|
-
message: referenceElement.resolve(message),
|
|
144
|
-
};
|
|
210
|
+
result.description = `${result.message.name} <${result.message.id}>`;
|
|
145
211
|
|
|
146
|
-
|
|
212
|
+
return result;
|
|
213
|
+
};
|
|
147
214
|
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
}
|
|
215
|
+
proto._debug = function debug(msg) {
|
|
216
|
+
this.logger.debug(`<${this.executionId} (${this.id})> ${msg}`);
|
|
217
|
+
};
|
package/src/tasks/ScriptTask.js
CHANGED
|
@@ -4,46 +4,43 @@ import { ActivityError } from '../error/Errors';
|
|
|
4
4
|
import {cloneContent, cloneMessage} from '../messageHelper';
|
|
5
5
|
|
|
6
6
|
export default function ScriptTask(activityDef, context) {
|
|
7
|
-
return Activity(ScriptTaskBehaviour, activityDef, context);
|
|
7
|
+
return new Activity(ScriptTaskBehaviour, activityDef, context);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export function ScriptTaskBehaviour(activity) {
|
|
11
|
-
const {id, type, behaviour
|
|
11
|
+
const {id, type, behaviour} = activity;
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
this.id = id;
|
|
14
|
+
this.type = type;
|
|
15
|
+
this.scriptFormat = behaviour.scriptFormat;
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
this.loopCharacteristics = behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
|
|
18
|
+
this.activity = activity;
|
|
19
|
+
const environment = this.environment = activity.environment;
|
|
16
20
|
|
|
17
21
|
environment.registerScript(activity);
|
|
22
|
+
}
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
execute
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return source;
|
|
27
|
-
|
|
28
|
-
function execute(executeMessage) {
|
|
29
|
-
const content = executeMessage.content;
|
|
30
|
-
if (loopCharacteristics && content.isRootScope) {
|
|
31
|
-
return loopCharacteristics.execute(executeMessage);
|
|
32
|
-
}
|
|
24
|
+
ScriptTaskBehaviour.prototype.execute = function execute(executeMessage) {
|
|
25
|
+
const executeContent = executeMessage.content;
|
|
26
|
+
const loopCharacteristics = this.loopCharacteristics;
|
|
27
|
+
if (loopCharacteristics && executeContent.isRootScope) {
|
|
28
|
+
return loopCharacteristics.execute(executeMessage);
|
|
29
|
+
}
|
|
33
30
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
31
|
+
const activity = this.activity, scriptFormat = this.scriptFormat;
|
|
32
|
+
const script = this.environment.getScript(scriptFormat, activity, cloneMessage(executeMessage));
|
|
33
|
+
if (!script) {
|
|
34
|
+
return activity.emitFatal(new ActivityError(`Script format ${scriptFormat} is unsupported or was not registered for <${activity.id}>`, executeMessage), executeContent);
|
|
35
|
+
}
|
|
38
36
|
|
|
39
|
-
|
|
37
|
+
return script.execute(ExecutionScope(activity, executeMessage), scriptCallback);
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
return broker.publish('execution', 'execute.completed', cloneContent(content, {output}));
|
|
39
|
+
function scriptCallback(err, output) {
|
|
40
|
+
if (err) {
|
|
41
|
+
activity.logger.error(`<${executeContent.executionId} (${activity.id})>`, err);
|
|
42
|
+
return activity.broker.publish('execution', 'execute.error', cloneContent(executeContent, {error: new ActivityError(err.message, executeMessage, err)}, {mandatory: true}));
|
|
47
43
|
}
|
|
44
|
+
return activity.broker.publish('execution', 'execute.completed', cloneContent(executeContent, {output}));
|
|
48
45
|
}
|
|
49
|
-
}
|
|
46
|
+
};
|
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
import ExecutionScope from '../activity/ExecutionScope';
|
|
2
2
|
|
|
3
3
|
export default function ServiceImplementation(activity) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
type,
|
|
11
|
-
implementation,
|
|
12
|
-
execute,
|
|
13
|
-
};
|
|
4
|
+
this.type = `${activity.type}:implementation`;
|
|
5
|
+
this.implementation = activity.behaviour.implementation;
|
|
6
|
+
this.activity = activity;
|
|
7
|
+
}
|
|
14
8
|
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
ServiceImplementation.prototype.execute = function execute(executionMessage, callback) {
|
|
10
|
+
const activity = this.activity;
|
|
11
|
+
const implementation = this.implementation;
|
|
12
|
+
const serviceFn = activity.environment.resolveExpression(implementation, executionMessage);
|
|
17
13
|
|
|
18
|
-
|
|
14
|
+
if (typeof serviceFn !== 'function') return callback(new Error(`Implementation ${implementation} did not resolve to a function`));
|
|
19
15
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
16
|
+
serviceFn.call(activity, ExecutionScope(activity, executionMessage), (err, ...args) => {
|
|
17
|
+
callback(err, args);
|
|
18
|
+
});
|
|
19
|
+
};
|
package/src/tasks/ServiceTask.js
CHANGED
|
@@ -3,80 +3,87 @@ import {ActivityError} from '../error/Errors';
|
|
|
3
3
|
import {cloneMessage, cloneContent} from '../messageHelper';
|
|
4
4
|
|
|
5
5
|
export default function ServiceTask(activityDef, context) {
|
|
6
|
-
return Activity(ServiceTaskBehaviour, activityDef, context);
|
|
6
|
+
return new Activity(ServiceTaskBehaviour, activityDef, context);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export function ServiceTaskBehaviour(activity) {
|
|
10
|
-
const {id, type,
|
|
11
|
-
const loopCharacteristics = behaviour.loopCharacteristics && behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
|
|
10
|
+
const {id, type, behaviour} = activity;
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
this.id = id;
|
|
13
|
+
this.type = type;
|
|
14
|
+
this.loopCharacteristics = behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
|
|
15
|
+
this.activity = activity;
|
|
16
|
+
this.environment = activity.environment;
|
|
17
|
+
this.broker = activity.broker;
|
|
18
|
+
}
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
const proto = ServiceTaskBehaviour.prototype;
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
proto.execute = function execute(executeMessage) {
|
|
23
|
+
const executeContent = executeMessage.content;
|
|
24
|
+
const loopCharacteristics = this.loopCharacteristics;
|
|
25
|
+
if (loopCharacteristics && executeContent.isRootScope) {
|
|
26
|
+
return loopCharacteristics.execute(executeMessage);
|
|
27
|
+
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
const executionId = executeContent.executionId;
|
|
30
|
+
const service = this.service = this.getService(executeMessage);
|
|
31
|
+
if (!service) return this.activity.emitFatal(new ActivityError(`<${this.id}> service not defined`, executeMessage), executeContent);
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
const broker = this.broker;
|
|
34
|
+
broker.subscribeTmp('api', `activity.#.${executionId}`, (...args) => this._onApiMessage(executeMessage, ...args), {consumerTag: `_api-${executionId}`});
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
return service.execute(executeMessage, (err, output) => {
|
|
37
|
+
broker.cancel(`_api-${executionId}`);
|
|
38
|
+
if (err) {
|
|
39
|
+
this.activity.logger.error(`<${executionId} (${this.id})>`, err);
|
|
40
|
+
return broker.publish('execution', 'execute.error', cloneContent(executeContent, {error: new ActivityError(err.message, executeMessage, err)}, {mandatory: true}));
|
|
41
|
+
}
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
return broker.publish('execution', 'execute.completed', cloneContent(executeContent, {output, state: 'complete'}));
|
|
44
|
+
});
|
|
45
|
+
};
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
logger.debug(`<${content.executionId} (${id})> discarded`);
|
|
50
|
-
return broker.publish('execution', 'execute.discard', cloneContent(content, {state: 'discard'}));
|
|
51
|
-
}
|
|
52
|
-
if (message.properties.type === 'stop') {
|
|
53
|
-
broker.cancel(`_api-${executionId}`);
|
|
54
|
-
if (service && service.stop) service.stop(message);
|
|
55
|
-
return logger.debug(`<${content.executionId} (${id})> stopped`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
47
|
+
proto.getService = function getService(message) {
|
|
48
|
+
let Service = this.activity.behaviour.Service;
|
|
49
|
+
if (!Service) {
|
|
50
|
+
Service = this.environment.settings.enableDummyService ? DummyService : null;
|
|
58
51
|
}
|
|
52
|
+
return Service && new Service(this.activity, cloneMessage(message));
|
|
53
|
+
};
|
|
59
54
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
proto._onApiMessage = function onApiMessage(executeMessage, _, message) {
|
|
56
|
+
const broker = this.broker;
|
|
57
|
+
switch (message.properties.type) {
|
|
58
|
+
case 'discard': {
|
|
59
|
+
const executionId = executeMessage.content.executionId;
|
|
60
|
+
broker.cancel(`_api-${executionId}`);
|
|
61
|
+
const service = this.service;
|
|
62
|
+
if (service) {
|
|
63
|
+
if (service.discard) service.discard(message);
|
|
64
|
+
else if (service.stop) service.stop(message);
|
|
65
|
+
}
|
|
66
|
+
this.activity.logger.debug(`<${executionId} (${this.id})> discarded`);
|
|
67
|
+
return broker.publish('execution', 'execute.discard', cloneContent(executeMessage.content, {state: 'discard'}));
|
|
64
68
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
type: 'dummyservice',
|
|
73
|
-
execute: executeDummyService,
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
function executeDummyService(...args) {
|
|
77
|
-
logger.debug(`<${id}> executing dummy service`);
|
|
78
|
-
const next = args.pop();
|
|
79
|
-
next();
|
|
69
|
+
case 'stop': {
|
|
70
|
+
const executionId = executeMessage.content.executionId;
|
|
71
|
+
broker.cancel(`_api-${executionId}`);
|
|
72
|
+
const service = this.service;
|
|
73
|
+
if (service && service.stop) service.stop(message);
|
|
74
|
+
return this.activity.logger.debug(`<${executionId} (${this.id})> stopped`);
|
|
80
75
|
}
|
|
81
76
|
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
function DummyService(activity) {
|
|
80
|
+
this.type = 'dummyservice';
|
|
81
|
+
this.activity = activity;
|
|
82
82
|
}
|
|
83
|
+
|
|
84
|
+
DummyService.prototype.execute = function executeDummyService(...args) {
|
|
85
|
+
const activity = this.activity;
|
|
86
|
+
activity.logger.debug(`<${activity.id}> executing dummy service`);
|
|
87
|
+
const next = args.pop();
|
|
88
|
+
next();
|
|
89
|
+
};
|