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