bpmn-elements 6.0.1 → 8.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +341 -0
- package/README.md +3 -0
- package/dist/index.js +52 -44
- package/dist/src/Api.js +77 -76
- package/dist/src/Context.js +176 -172
- package/dist/src/Environment.js +110 -102
- package/dist/src/EventBroker.js +89 -88
- package/dist/src/ExtensionsMapper.js +2 -2
- package/dist/src/MessageFormatter.js +164 -95
- package/dist/src/Scripts.js +6 -2
- package/dist/src/activity/Activity.js +1105 -916
- package/dist/src/activity/ActivityExecution.js +342 -297
- package/dist/src/activity/Dummy.js +3 -3
- package/dist/src/definition/Definition.js +498 -444
- package/dist/src/definition/DefinitionExecution.js +710 -408
- package/dist/src/error/Errors.js +17 -7
- package/dist/src/eventDefinitions/CancelEventDefinition.js +190 -150
- package/dist/src/eventDefinitions/CompensateEventDefinition.js +194 -161
- package/dist/src/eventDefinitions/ConditionalEventDefinition.js +197 -135
- package/dist/src/eventDefinitions/ErrorEventDefinition.js +207 -165
- package/dist/src/eventDefinitions/EscalationEventDefinition.js +175 -141
- package/dist/src/eventDefinitions/EventDefinitionExecution.js +157 -129
- package/dist/src/eventDefinitions/LinkEventDefinition.js +174 -149
- package/dist/src/eventDefinitions/MessageEventDefinition.js +213 -176
- package/dist/src/eventDefinitions/SignalEventDefinition.js +203 -161
- package/dist/src/eventDefinitions/TerminateEventDefinition.js +21 -23
- package/dist/src/eventDefinitions/TimerEventDefinition.js +243 -228
- package/dist/src/events/BoundaryEvent.js +180 -144
- package/dist/src/events/EndEvent.js +18 -23
- package/dist/src/events/IntermediateCatchEvent.js +44 -58
- package/dist/src/events/IntermediateThrowEvent.js +18 -23
- package/dist/src/events/StartEvent.js +109 -94
- package/dist/src/flows/Association.js +94 -100
- package/dist/src/flows/MessageFlow.js +86 -103
- package/dist/src/flows/SequenceFlow.js +173 -182
- package/dist/src/gateways/EventBasedGateway.js +88 -84
- package/dist/src/gateways/ExclusiveGateway.js +13 -16
- package/dist/src/gateways/InclusiveGateway.js +11 -14
- package/dist/src/gateways/ParallelGateway.js +11 -14
- package/dist/src/getPropertyValue.js +34 -34
- package/dist/src/io/BpmnIO.js +17 -14
- package/dist/src/io/EnvironmentDataObject.js +33 -29
- package/dist/src/io/EnvironmentDataStore.js +33 -29
- package/dist/src/io/EnvironmentDataStoreReference.js +35 -31
- package/dist/src/io/InputOutputSpecification.js +177 -168
- package/dist/src/io/Properties.js +117 -124
- package/dist/src/messageHelper.js +1 -1
- package/dist/src/process/Process.js +439 -362
- package/dist/src/process/ProcessExecution.js +748 -646
- package/dist/src/shared.js +2 -2
- package/dist/src/tasks/CallActivity.js +160 -0
- package/dist/src/tasks/LoopCharacteristics.js +309 -330
- package/dist/src/tasks/ReceiveTask.js +233 -182
- package/dist/src/tasks/ScriptTask.js +35 -41
- package/dist/src/tasks/ServiceImplementation.js +13 -20
- package/dist/src/tasks/ServiceTask.js +82 -75
- package/dist/src/tasks/SignalTask.js +97 -93
- package/dist/src/tasks/StandardLoopCharacteristics.js +1 -1
- package/dist/src/tasks/SubProcess.js +193 -175
- package/dist/src/tasks/Task.js +17 -19
- package/index.js +2 -0
- package/package.json +16 -16
- package/src/Api.js +65 -59
- package/src/Context.js +145 -140
- package/src/Environment.js +116 -100
- package/src/EventBroker.js +67 -68
- package/src/ExtensionsMapper.js +2 -2
- package/src/MessageFormatter.js +132 -74
- package/src/activity/Activity.js +914 -776
- package/src/activity/ActivityExecution.js +293 -247
- package/src/activity/Dummy.js +2 -2
- package/src/definition/Definition.js +437 -401
- package/src/definition/DefinitionExecution.js +598 -340
- package/src/error/Errors.js +11 -6
- package/src/eventDefinitions/CancelEventDefinition.js +164 -121
- package/src/eventDefinitions/CompensateEventDefinition.js +159 -124
- package/src/eventDefinitions/ConditionalEventDefinition.js +147 -104
- package/src/eventDefinitions/ErrorEventDefinition.js +190 -131
- package/src/eventDefinitions/EscalationEventDefinition.js +139 -101
- package/src/eventDefinitions/EventDefinitionExecution.js +127 -95
- package/src/eventDefinitions/LinkEventDefinition.js +160 -129
- package/src/eventDefinitions/MessageEventDefinition.js +178 -121
- package/src/eventDefinitions/SignalEventDefinition.js +162 -106
- package/src/eventDefinitions/TerminateEventDefinition.js +19 -19
- package/src/eventDefinitions/TimerEventDefinition.js +202 -167
- package/src/events/BoundaryEvent.js +156 -115
- package/src/events/EndEvent.js +15 -18
- package/src/events/IntermediateCatchEvent.js +40 -44
- package/src/events/IntermediateThrowEvent.js +15 -18
- package/src/events/StartEvent.js +84 -50
- package/src/flows/Association.js +98 -112
- package/src/flows/MessageFlow.js +81 -97
- package/src/flows/SequenceFlow.js +146 -160
- package/src/gateways/EventBasedGateway.js +75 -68
- package/src/gateways/ExclusiveGateway.js +8 -13
- package/src/gateways/InclusiveGateway.js +8 -13
- package/src/gateways/ParallelGateway.js +8 -13
- package/src/getPropertyValue.js +34 -33
- package/src/io/BpmnIO.js +20 -15
- package/src/io/EnvironmentDataObject.js +29 -18
- package/src/io/EnvironmentDataStore.js +29 -18
- package/src/io/EnvironmentDataStoreReference.js +31 -20
- package/src/io/InputOutputSpecification.js +154 -157
- package/src/io/Properties.js +95 -97
- package/src/process/Process.js +378 -333
- package/src/process/ProcessExecution.js +603 -553
- package/src/tasks/CallActivity.js +130 -0
- package/src/tasks/LoopCharacteristics.js +290 -289
- package/src/tasks/ReceiveTask.js +174 -107
- package/src/tasks/ScriptTask.js +27 -30
- package/src/tasks/ServiceImplementation.js +13 -18
- package/src/tasks/ServiceTask.js +67 -60
- package/src/tasks/SignalTask.js +77 -52
- package/src/tasks/StandardLoopCharacteristics.js +1 -1
- package/src/tasks/SubProcess.js +184 -157
- package/src/tasks/Task.js +15 -19
package/src/process/Process.js
CHANGED
|
@@ -2,389 +2,434 @@ import ProcessExecution from './ProcessExecution';
|
|
|
2
2
|
import {getUniqueId} from '../shared';
|
|
3
3
|
import {ProcessApi} from '../Api';
|
|
4
4
|
import {ProcessBroker} from '../EventBroker';
|
|
5
|
-
import {cloneMessage, cloneContent} from '../messageHelper';
|
|
5
|
+
import {cloneMessage, cloneContent, cloneParent} from '../messageHelper';
|
|
6
6
|
import {makeErrorFromMessage} from '../error/Errors';
|
|
7
7
|
|
|
8
|
+
const kConsuming = Symbol.for('consuming');
|
|
9
|
+
const kCounters = Symbol.for('counters');
|
|
10
|
+
const kExec = Symbol.for('execution');
|
|
11
|
+
const kExecuteMessage = Symbol.for('executeMessage');
|
|
12
|
+
const kExtensions = Symbol.for('extensions');
|
|
13
|
+
const kMessageHandlers = Symbol.for('messageHandlers');
|
|
14
|
+
const kStateMessage = Symbol.for('stateMessage');
|
|
15
|
+
const kStatus = Symbol.for('status');
|
|
16
|
+
const kStopped = Symbol.for('stopped');
|
|
17
|
+
|
|
8
18
|
export default Process;
|
|
9
19
|
|
|
10
20
|
export function Process(processDef, context) {
|
|
11
21
|
const {id, type = 'process', name, parent, behaviour = {}} = processDef;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
22
|
+
this.id = id;
|
|
23
|
+
this.type = type;
|
|
24
|
+
this.name = name;
|
|
25
|
+
this.parent = parent ? cloneParent(parent) : {};
|
|
26
|
+
this.behaviour = behaviour;
|
|
16
27
|
|
|
17
|
-
|
|
28
|
+
const {isExecutable} = behaviour;
|
|
29
|
+
this.isExecutable = isExecutable;
|
|
18
30
|
|
|
19
|
-
|
|
31
|
+
const environment = this.environment = context.environment;
|
|
32
|
+
this.context = context;
|
|
33
|
+
this[kCounters] = {
|
|
20
34
|
completed: 0,
|
|
21
35
|
discarded: 0,
|
|
22
|
-
terminated: 0,
|
|
23
36
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
},
|
|
40
|
-
get stopped() {
|
|
41
|
-
return stopped;
|
|
42
|
-
},
|
|
43
|
-
get execution() {
|
|
44
|
-
return execution;
|
|
45
|
-
},
|
|
46
|
-
get isRunning() {
|
|
47
|
-
if (!consumingRunQ) return false;
|
|
48
|
-
return !!status;
|
|
49
|
-
},
|
|
50
|
-
context,
|
|
51
|
-
environment,
|
|
52
|
-
parent: {...parent},
|
|
53
|
-
logger,
|
|
54
|
-
getApi,
|
|
55
|
-
getActivities,
|
|
56
|
-
getActivityById,
|
|
57
|
-
getSequenceFlows,
|
|
58
|
-
getPostponed,
|
|
59
|
-
getStartActivities,
|
|
60
|
-
getState,
|
|
61
|
-
init,
|
|
62
|
-
recover,
|
|
63
|
-
resume,
|
|
64
|
-
run,
|
|
65
|
-
sendMessage,
|
|
66
|
-
shake,
|
|
67
|
-
signal,
|
|
68
|
-
cancelActivity,
|
|
69
|
-
stop,
|
|
37
|
+
this[kConsuming] = false;
|
|
38
|
+
this[kExec] = {};
|
|
39
|
+
this[kStatus] = undefined;
|
|
40
|
+
this[kStopped] = false;
|
|
41
|
+
|
|
42
|
+
const {broker, on, once, waitFor} = ProcessBroker(this);
|
|
43
|
+
this.broker = broker;
|
|
44
|
+
this.on = on;
|
|
45
|
+
this.once = once;
|
|
46
|
+
this.waitFor = waitFor;
|
|
47
|
+
|
|
48
|
+
this[kMessageHandlers] = {
|
|
49
|
+
onApiMessage: this._onApiMessage.bind(this),
|
|
50
|
+
onRunMessage: this._onRunMessage.bind(this),
|
|
51
|
+
onExecutionMessage: this._onExecutionMessage.bind(this),
|
|
70
52
|
};
|
|
71
53
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
processApi.on = on;
|
|
75
|
-
processApi.once = once;
|
|
76
|
-
processApi.waitFor = waitFor;
|
|
77
|
-
|
|
78
|
-
const runQ = broker.getQueue('run-q');
|
|
79
|
-
const executionQ = broker.getQueue('execution-q');
|
|
80
|
-
|
|
81
|
-
Object.defineProperty(processApi, 'broker', {
|
|
82
|
-
enumerable: true,
|
|
83
|
-
get: () => broker,
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const extensions = context.loadExtensions(processApi);
|
|
87
|
-
Object.defineProperty(processApi, 'extensions', {
|
|
88
|
-
enumerable: true,
|
|
89
|
-
get: () => extensions,
|
|
90
|
-
});
|
|
54
|
+
this.logger = environment.Logger(type.toLowerCase());
|
|
91
55
|
|
|
92
|
-
|
|
56
|
+
this[kExtensions] = context.loadExtensions(this);
|
|
57
|
+
}
|
|
93
58
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
59
|
+
const proto = Process.prototype;
|
|
60
|
+
|
|
61
|
+
Object.defineProperty(proto, 'counters', {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get() {
|
|
64
|
+
return {...this[kCounters]};
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
Object.defineProperty(proto, 'extensions', {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
get() {
|
|
71
|
+
return this[kExtensions];
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
Object.defineProperty(proto, 'stopped', {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
get() {
|
|
78
|
+
return this[kStopped];
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
Object.defineProperty(proto, 'isRunning', {
|
|
83
|
+
enumerable: true,
|
|
84
|
+
get() {
|
|
85
|
+
if (!this[kConsuming]) return false;
|
|
86
|
+
return !!this.status;
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
Object.defineProperty(proto, 'executionId', {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
get() {
|
|
93
|
+
const {executionId, initExecutionId} = this[kExec];
|
|
94
|
+
return executionId || initExecutionId;
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
Object.defineProperty(proto, 'execution', {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get() {
|
|
101
|
+
return this[kExec].execution;
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
Object.defineProperty(proto, 'status', {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
get() {
|
|
108
|
+
return this[kStatus];
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
proto.init = function init(useAsExecutionId) {
|
|
113
|
+
const exec = this[kExec];
|
|
114
|
+
const initExecutionId = exec.initExecutionId = useAsExecutionId || getUniqueId(this.id);
|
|
115
|
+
this._debug(`initialized with executionId <${initExecutionId}>`);
|
|
116
|
+
this._publishEvent('init', this._createMessage({executionId: initExecutionId}));
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
proto.run = function run(runContent) {
|
|
120
|
+
if (this.isRunning) throw new Error(`process <${this.id}> is already running`);
|
|
121
|
+
|
|
122
|
+
const exec = this[kExec];
|
|
123
|
+
const executionId = exec.executionId = exec.initExecutionId || getUniqueId(this.id);
|
|
124
|
+
exec.initExecutionId = undefined;
|
|
125
|
+
|
|
126
|
+
const content = this._createMessage({...runContent, executionId});
|
|
127
|
+
|
|
128
|
+
const broker = this.broker;
|
|
129
|
+
broker.publish('run', 'run.enter', content);
|
|
130
|
+
broker.publish('run', 'run.start', cloneContent(content));
|
|
131
|
+
broker.publish('run', 'run.execute', cloneContent(content));
|
|
132
|
+
|
|
133
|
+
this._activateRunConsumers();
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
proto.resume = function resume() {
|
|
137
|
+
if (this.isRunning) throw new Error(`cannot resume running process <${this.id}>`);
|
|
138
|
+
if (!this.status) return this;
|
|
139
|
+
|
|
140
|
+
this[kStopped] = false;
|
|
141
|
+
|
|
142
|
+
const content = this._createMessage();
|
|
143
|
+
this.broker.publish('run', 'run.resume', content, {persistent: false});
|
|
144
|
+
this._activateRunConsumers();
|
|
145
|
+
return this;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
proto.recover = function recover(state) {
|
|
149
|
+
if (this.isRunning) throw new Error(`cannot recover running process <${this.id}>`);
|
|
150
|
+
if (!state) return this;
|
|
151
|
+
|
|
152
|
+
this[kStopped] = !!state.stopped;
|
|
153
|
+
this[kStatus] = state.status;
|
|
154
|
+
const exec = this[kExec];
|
|
155
|
+
exec.executionId = state.executionId;
|
|
156
|
+
this[kCounters] = {...this[kCounters], ...state.counters};
|
|
157
|
+
this.environment.recover(state.environment);
|
|
158
|
+
|
|
159
|
+
if (state.execution) {
|
|
160
|
+
exec.execution = new ProcessExecution(this, this.context).recover(state.execution);
|
|
98
161
|
}
|
|
99
162
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
163
|
+
this.broker.recover(state.broker);
|
|
164
|
+
|
|
165
|
+
return this;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
proto.shake = function shake(startId) {
|
|
169
|
+
if (this.isRunning) return this.execution.shake(startId);
|
|
170
|
+
return new ProcessExecution(this, this.context).shake(startId);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
proto.stop = function stop() {
|
|
174
|
+
if (!this.isRunning) return;
|
|
175
|
+
this.getApi().stop();
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
proto.getApi = function getApi(message) {
|
|
179
|
+
const execution = this.execution;
|
|
180
|
+
if (execution) return execution.getApi(message);
|
|
181
|
+
return ProcessApi(this.broker, message || this[kStateMessage]);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
proto.signal = function signal(message) {
|
|
185
|
+
return this.getApi().signal(message, {delegate: true});
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
proto.getState = function getState() {
|
|
189
|
+
return this._createMessage({
|
|
190
|
+
environment: this.environment.getState(),
|
|
191
|
+
status: this.status,
|
|
192
|
+
stopped: this.stopped,
|
|
193
|
+
counters: this.counters,
|
|
194
|
+
broker: this.broker.getState(true),
|
|
195
|
+
execution: this.execution && this.execution.getState(),
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
proto.cancelActivity = function cancelActivity(message) {
|
|
200
|
+
return this.getApi().cancel(message, {delegate: true});
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
proto._activateRunConsumers = function activateRunConsumers() {
|
|
204
|
+
this[kConsuming] = true;
|
|
205
|
+
const broker = this.broker;
|
|
206
|
+
const {onApiMessage, onRunMessage} = this[kMessageHandlers];
|
|
207
|
+
broker.subscribeTmp('api', `process.*.${this.executionId}`, onApiMessage, {noAck: true, consumerTag: '_process-api', priority: 100});
|
|
208
|
+
broker.getQueue('run-q').assertConsumer(onRunMessage, {exclusive: true, consumerTag: '_process-run'});
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
proto._deactivateRunConsumers = function deactivateRunConsumers() {
|
|
212
|
+
const broker = this.broker;
|
|
213
|
+
broker.cancel('_process-api');
|
|
214
|
+
broker.cancel('_process-run');
|
|
215
|
+
broker.cancel('_process-execution');
|
|
216
|
+
this[kConsuming] = false;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
proto._onRunMessage = function onRunMessage(routingKey, message) {
|
|
220
|
+
const {content, fields} = message;
|
|
221
|
+
|
|
222
|
+
if (routingKey === 'run.resume') {
|
|
223
|
+
return this._onResumeMessage(message);
|
|
113
224
|
}
|
|
114
225
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (!status) return processApi;
|
|
226
|
+
const exec = this[kExec];
|
|
227
|
+
this[kStateMessage] = message;
|
|
118
228
|
|
|
119
|
-
|
|
229
|
+
switch (routingKey) {
|
|
230
|
+
case 'run.enter': {
|
|
231
|
+
this._debug('enter');
|
|
120
232
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
activateRunConsumers();
|
|
124
|
-
return processApi;
|
|
125
|
-
}
|
|
233
|
+
this[kStatus] = 'entered';
|
|
234
|
+
if (fields.redelivered) break;
|
|
126
235
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (!state) return processApi;
|
|
236
|
+
exec.execution = undefined;
|
|
237
|
+
this._publishEvent('enter', content);
|
|
130
238
|
|
|
131
|
-
|
|
132
|
-
status = state.status;
|
|
133
|
-
executionId = state.executionId;
|
|
134
|
-
counters = {...counters, ...state.counters};
|
|
135
|
-
|
|
136
|
-
if (state.execution) {
|
|
137
|
-
execution = ProcessExecution(processApi, context).recover(state.execution);
|
|
239
|
+
break;
|
|
138
240
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
function shake(startId) {
|
|
146
|
-
if (processApi.isRunning) return execution.shake(startId);
|
|
147
|
-
return ProcessExecution(processApi, context).shake(startId);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function activateRunConsumers() {
|
|
151
|
-
consumingRunQ = true;
|
|
152
|
-
broker.subscribeTmp('api', `process.*.${executionId}`, onApiMessage, {noAck: true, consumerTag: '_process-api', priority: 100});
|
|
153
|
-
runQ.assertConsumer(onRunMessage, {exclusive: true, consumerTag: '_process-run'});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function deactivateRunConsumers() {
|
|
157
|
-
broker.cancel('_process-api');
|
|
158
|
-
broker.cancel('_process-run');
|
|
159
|
-
broker.cancel('_process-execution');
|
|
160
|
-
consumingRunQ = false;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function stop() {
|
|
164
|
-
if (!processApi.isRunning) return;
|
|
165
|
-
getApi().stop();
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function getApi(message) {
|
|
169
|
-
if (execution) return execution.getApi(message);
|
|
170
|
-
return ProcessApi(broker, message || stateMessage);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function signal(message) {
|
|
174
|
-
return getApi().signal(message, {delegate: true});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function cancelActivity(message) {
|
|
178
|
-
return getApi().cancel(message, {delegate: true});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function onRunMessage(routingKey, message) {
|
|
182
|
-
const {content, ack, fields} = message;
|
|
183
|
-
|
|
184
|
-
if (routingKey === 'run.resume') {
|
|
185
|
-
return onResumeMessage();
|
|
241
|
+
case 'run.start': {
|
|
242
|
+
this._debug('start');
|
|
243
|
+
this[kStatus] = 'start';
|
|
244
|
+
this._publishEvent('start', content);
|
|
245
|
+
break;
|
|
186
246
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
logger.debug(`<${id}> enter`);
|
|
193
|
-
|
|
194
|
-
status = 'entered';
|
|
195
|
-
if (fields.redelivered) break;
|
|
196
|
-
|
|
197
|
-
execution = undefined;
|
|
198
|
-
publishEvent('enter', content);
|
|
199
|
-
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
202
|
-
case 'run.start': {
|
|
203
|
-
logger.debug(`<${id}> start`);
|
|
204
|
-
status = 'start';
|
|
205
|
-
publishEvent('start', content);
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
208
|
-
case 'run.execute': {
|
|
209
|
-
status = 'executing';
|
|
210
|
-
const executeMessage = cloneMessage(message);
|
|
211
|
-
if (fields.redelivered && !execution) {
|
|
212
|
-
executeMessage.fields.redelivered = undefined;
|
|
213
|
-
}
|
|
214
|
-
postponedMessage = message;
|
|
215
|
-
executionQ.assertConsumer(onExecutionMessage, {exclusive: true, consumerTag: '_process-execution'});
|
|
216
|
-
execution = execution || ProcessExecution(processApi, context);
|
|
217
|
-
return execution.execute(executeMessage);
|
|
218
|
-
}
|
|
219
|
-
case 'run.error': {
|
|
220
|
-
publishEvent('error', cloneContent(content, {
|
|
221
|
-
error: fields.redelivered ? makeErrorFromMessage(message) : content.error,
|
|
222
|
-
}));
|
|
223
|
-
break;
|
|
224
|
-
}
|
|
225
|
-
case 'run.end': {
|
|
226
|
-
status = 'end';
|
|
227
|
-
|
|
228
|
-
if (fields.redelivered) break;
|
|
229
|
-
logger.debug(`<${id}> completed`);
|
|
230
|
-
|
|
231
|
-
counters.completed++;
|
|
232
|
-
|
|
233
|
-
broker.publish('run', 'run.leave', content);
|
|
234
|
-
publishEvent('end', content);
|
|
235
|
-
break;
|
|
247
|
+
case 'run.execute': {
|
|
248
|
+
this[kStatus] = 'executing';
|
|
249
|
+
const executeMessage = cloneMessage(message);
|
|
250
|
+
if (fields.redelivered && !exec.execution) {
|
|
251
|
+
executeMessage.fields.redelivered = undefined;
|
|
236
252
|
}
|
|
237
|
-
|
|
238
|
-
status = 'discarded';
|
|
239
|
-
if (fields.redelivered) break;
|
|
253
|
+
this[kExecuteMessage] = message;
|
|
240
254
|
|
|
241
|
-
|
|
255
|
+
this.broker.getQueue('execution-q').assertConsumer(this[kMessageHandlers].onExecutionMessage, {
|
|
256
|
+
exclusive: true,
|
|
257
|
+
consumerTag: '_process-execution',
|
|
258
|
+
});
|
|
242
259
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
case 'run.leave': {
|
|
247
|
-
status = undefined;
|
|
248
|
-
broker.cancel('_process-api');
|
|
249
|
-
publishEvent('leave');
|
|
250
|
-
break;
|
|
251
|
-
}
|
|
260
|
+
const execution = exec.execution = exec.execution || new ProcessExecution(this, this.context);
|
|
261
|
+
return execution.execute(executeMessage);
|
|
252
262
|
}
|
|
263
|
+
case 'run.error': {
|
|
264
|
+
this[kStatus] = 'errored';
|
|
265
|
+
this._publishEvent('error', cloneContent(content, {
|
|
266
|
+
error: fields.redelivered ? makeErrorFromMessage(message) : content.error,
|
|
267
|
+
}));
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
case 'run.end': {
|
|
271
|
+
this[kStatus] = 'end';
|
|
253
272
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
function onResumeMessage() {
|
|
257
|
-
message.ack();
|
|
258
|
-
|
|
259
|
-
switch (stateMessage.fields.routingKey) {
|
|
260
|
-
case 'run.enter':
|
|
261
|
-
case 'run.start':
|
|
262
|
-
case 'run.discarded':
|
|
263
|
-
case 'run.end':
|
|
264
|
-
case 'run.leave':
|
|
265
|
-
break;
|
|
266
|
-
default:
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
273
|
+
if (fields.redelivered) break;
|
|
274
|
+
this._debug('completed');
|
|
269
275
|
|
|
270
|
-
|
|
276
|
+
this[kCounters].completed++;
|
|
271
277
|
|
|
272
|
-
|
|
278
|
+
this.broker.publish('run', 'run.leave', content);
|
|
273
279
|
|
|
274
|
-
|
|
280
|
+
this._publishEvent('end', content);
|
|
281
|
+
break;
|
|
275
282
|
}
|
|
276
|
-
|
|
283
|
+
case 'run.discarded': {
|
|
284
|
+
this[kStatus] = 'discarded';
|
|
285
|
+
if (fields.redelivered) break;
|
|
277
286
|
|
|
278
|
-
|
|
279
|
-
const content = message.content;
|
|
280
|
-
const messageType = message.properties.type;
|
|
281
|
-
message.ack();
|
|
287
|
+
this[kCounters].discarded++;
|
|
282
288
|
|
|
283
|
-
|
|
284
|
-
case 'stopped': {
|
|
285
|
-
return onStop();
|
|
286
|
-
}
|
|
287
|
-
case 'error': {
|
|
288
|
-
broker.publish('run', 'run.error', content);
|
|
289
|
-
broker.publish('run', 'run.discarded', content);
|
|
290
|
-
break;
|
|
291
|
-
}
|
|
292
|
-
case 'discard':
|
|
293
|
-
broker.publish('run', 'run.discarded', content);
|
|
294
|
-
break;
|
|
295
|
-
default: {
|
|
296
|
-
broker.publish('run', 'run.end', content);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
289
|
+
this.broker.publish('run', 'run.leave', content);
|
|
299
290
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
postponedMessage = null;
|
|
303
|
-
ackMessage.ack();
|
|
291
|
+
this._publishEvent('discarded', content);
|
|
292
|
+
break;
|
|
304
293
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
function sendMessage(message) {
|
|
313
|
-
const messageContent = message.content;
|
|
314
|
-
if (!messageContent) return;
|
|
315
|
-
|
|
316
|
-
let targetsFound = false;
|
|
317
|
-
if (messageContent.target && messageContent.target.id && getActivityById(messageContent.target.id)) {
|
|
318
|
-
targetsFound = true;
|
|
319
|
-
} else if (messageContent.message && getStartActivities({referenceId: messageContent.message.id, referenceType: messageContent.message.messageType}).length) {
|
|
320
|
-
targetsFound = true;
|
|
294
|
+
case 'run.leave': {
|
|
295
|
+
this[kStatus] = undefined;
|
|
296
|
+
this.broker.cancel('_process-api');
|
|
297
|
+
const {output, ...rest} = content; // eslint-disable-line no-unused-vars
|
|
298
|
+
this._publishEvent('leave', rest);
|
|
299
|
+
break;
|
|
321
300
|
}
|
|
322
|
-
if (!targetsFound) return;
|
|
323
|
-
|
|
324
|
-
if (!status) run();
|
|
325
|
-
getApi().sendApiMessage(message.properties.type || 'message', cloneContent(messageContent), {delegate: true});
|
|
326
301
|
}
|
|
327
302
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
303
|
+
message.ack();
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
proto._onResumeMessage = function onResumeMessage(message) {
|
|
307
|
+
message.ack();
|
|
308
|
+
|
|
309
|
+
const stateMessage = this[kStateMessage];
|
|
310
|
+
switch (stateMessage.fields.routingKey) {
|
|
311
|
+
case 'run.enter':
|
|
312
|
+
case 'run.start':
|
|
313
|
+
case 'run.discarded':
|
|
314
|
+
case 'run.end':
|
|
315
|
+
case 'run.leave':
|
|
316
|
+
break;
|
|
317
|
+
default:
|
|
318
|
+
return;
|
|
331
319
|
}
|
|
332
320
|
|
|
333
|
-
|
|
334
|
-
if (execution) return execution.getActivities();
|
|
335
|
-
return context.getActivities(id);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
function getStartActivities(filterOptions) {
|
|
339
|
-
return context.getStartActivities(filterOptions, id);
|
|
340
|
-
}
|
|
321
|
+
if (!stateMessage.fields.redelivered) return;
|
|
341
322
|
|
|
342
|
-
|
|
343
|
-
if (execution) return execution.getSequenceFlows();
|
|
344
|
-
return context.getSequenceFlows();
|
|
345
|
-
}
|
|
323
|
+
this._debug(`resume from ${this.status}`);
|
|
346
324
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
return [];
|
|
350
|
-
}
|
|
325
|
+
return this.broker.publish('run', stateMessage.fields.routingKey, cloneContent(stateMessage.content), stateMessage.properties);
|
|
326
|
+
};
|
|
351
327
|
|
|
352
|
-
|
|
353
|
-
|
|
328
|
+
proto._onExecutionMessage = function onExecutionMessage(routingKey, message) {
|
|
329
|
+
const content = message.content;
|
|
330
|
+
const messageType = message.properties.type;
|
|
331
|
+
message.ack();
|
|
354
332
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
333
|
+
switch (messageType) {
|
|
334
|
+
case 'stopped': {
|
|
335
|
+
return this._onStop();
|
|
336
|
+
}
|
|
337
|
+
case 'error': {
|
|
338
|
+
this.broker.publish('run', 'run.error', content);
|
|
339
|
+
this.broker.publish('run', 'run.discarded', content);
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
case 'discard':
|
|
343
|
+
this.broker.publish('run', 'run.discarded', content);
|
|
344
|
+
break;
|
|
345
|
+
default: {
|
|
346
|
+
this.broker.publish('run', 'run.end', content);
|
|
361
347
|
}
|
|
362
348
|
}
|
|
363
349
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
350
|
+
const executeMessage = this[kExecuteMessage];
|
|
351
|
+
this[kExecuteMessage] = null;
|
|
352
|
+
executeMessage.ack();
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
proto._publishEvent = function publishEvent(state, content) {
|
|
356
|
+
const eventContent = this._createMessage({...content, state});
|
|
357
|
+
this.broker.publish('event', `process.${state}`, eventContent, {type: state, mandatory: state === 'error'});
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
proto.sendMessage = function sendMessage(message) {
|
|
361
|
+
const messageContent = message && message.content;
|
|
362
|
+
if (!messageContent) return;
|
|
363
|
+
|
|
364
|
+
let targetsFound = false;
|
|
365
|
+
if (messageContent.target && messageContent.target.id && this.getActivityById(messageContent.target.id)) {
|
|
366
|
+
targetsFound = true;
|
|
367
|
+
} else if (messageContent.message && this.getStartActivities({referenceId: messageContent.message.id, referenceType: messageContent.message.messageType}).length) {
|
|
368
|
+
targetsFound = true;
|
|
368
369
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
370
|
+
if (!targetsFound) return;
|
|
371
|
+
|
|
372
|
+
if (!this.status) this.run();
|
|
373
|
+
this.getApi().sendApiMessage(message.properties.type || 'message', cloneContent(messageContent), {delegate: true});
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
proto.getActivityById = function getActivityById(childId) {
|
|
377
|
+
const execution = this.execution;
|
|
378
|
+
if (execution) return execution.getActivityById(childId);
|
|
379
|
+
return this.context.getActivityById(childId);
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
proto.getActivities = function getActivities() {
|
|
383
|
+
const execution = this.execution;
|
|
384
|
+
if (execution) return execution.getActivities();
|
|
385
|
+
return this.context.getActivities(this.id);
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
proto.getStartActivities = function getStartActivities(filterOptions) {
|
|
389
|
+
return this.context.getStartActivities(filterOptions, this.id);
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
proto.getSequenceFlows = function getSequenceFlows() {
|
|
393
|
+
const execution = this.execution;
|
|
394
|
+
if (execution) return execution.getSequenceFlows();
|
|
395
|
+
return this.context.getSequenceFlows();
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
proto.getPostponed = function getPostponed(...args) {
|
|
399
|
+
const execution = this.execution;
|
|
400
|
+
if (!execution) return [];
|
|
401
|
+
return execution.getPostponed(...args);
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
proto._onApiMessage = function onApiMessage(routingKey, message) {
|
|
405
|
+
const messageType = message.properties.type;
|
|
406
|
+
|
|
407
|
+
switch (messageType) {
|
|
408
|
+
case 'stop': {
|
|
409
|
+
if (this.execution && !this.execution.completed) return;
|
|
410
|
+
this._onStop();
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
378
413
|
}
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
proto._onStop = function onStop() {
|
|
417
|
+
this[kStopped] = true;
|
|
418
|
+
this._deactivateRunConsumers();
|
|
419
|
+
return this._publishEvent('stop');
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
proto._createMessage = function createMessage(override) {
|
|
423
|
+
return {
|
|
424
|
+
id: this.id,
|
|
425
|
+
type: this.type,
|
|
426
|
+
name: this.name,
|
|
427
|
+
executionId: this.executionId,
|
|
428
|
+
parent: {...this.parent},
|
|
429
|
+
...override,
|
|
430
|
+
};
|
|
431
|
+
};
|
|
379
432
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
status,
|
|
384
|
-
stopped,
|
|
385
|
-
counters: {...counters},
|
|
386
|
-
broker: broker.getState(true),
|
|
387
|
-
execution: execution && execution.getState(),
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
}
|
|
433
|
+
proto._debug = function debug(msg) {
|
|
434
|
+
this.logger.debug(`<${this.id}> ${msg}`);
|
|
435
|
+
};
|