bpmn-elements 6.0.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +335 -0
- package/README.md +3 -0
- package/dist/index.js +52 -44
- package/dist/src/Api.js +77 -76
- package/dist/src/Context.js +176 -172
- package/dist/src/Environment.js +110 -102
- package/dist/src/EventBroker.js +89 -88
- package/dist/src/ExtensionsMapper.js +2 -2
- package/dist/src/MessageFormatter.js +164 -95
- package/dist/src/Scripts.js +6 -2
- package/dist/src/activity/Activity.js +1106 -916
- package/dist/src/activity/ActivityExecution.js +342 -297
- package/dist/src/activity/Dummy.js +3 -3
- package/dist/src/definition/Definition.js +498 -444
- package/dist/src/definition/DefinitionExecution.js +710 -408
- package/dist/src/error/Errors.js +17 -7
- package/dist/src/eventDefinitions/CancelEventDefinition.js +190 -150
- package/dist/src/eventDefinitions/CompensateEventDefinition.js +194 -161
- package/dist/src/eventDefinitions/ConditionalEventDefinition.js +197 -135
- package/dist/src/eventDefinitions/ErrorEventDefinition.js +207 -165
- package/dist/src/eventDefinitions/EscalationEventDefinition.js +175 -141
- package/dist/src/eventDefinitions/EventDefinitionExecution.js +157 -129
- package/dist/src/eventDefinitions/LinkEventDefinition.js +174 -149
- package/dist/src/eventDefinitions/MessageEventDefinition.js +213 -176
- package/dist/src/eventDefinitions/SignalEventDefinition.js +203 -161
- package/dist/src/eventDefinitions/TerminateEventDefinition.js +21 -23
- package/dist/src/eventDefinitions/TimerEventDefinition.js +243 -228
- package/dist/src/events/BoundaryEvent.js +180 -144
- package/dist/src/events/EndEvent.js +18 -23
- package/dist/src/events/IntermediateCatchEvent.js +44 -58
- package/dist/src/events/IntermediateThrowEvent.js +18 -23
- package/dist/src/events/StartEvent.js +109 -94
- package/dist/src/flows/Association.js +94 -100
- package/dist/src/flows/MessageFlow.js +86 -103
- package/dist/src/flows/SequenceFlow.js +173 -182
- package/dist/src/gateways/EventBasedGateway.js +88 -84
- package/dist/src/gateways/ExclusiveGateway.js +13 -16
- package/dist/src/gateways/InclusiveGateway.js +11 -14
- package/dist/src/gateways/ParallelGateway.js +11 -14
- package/dist/src/getPropertyValue.js +34 -34
- package/dist/src/io/BpmnIO.js +17 -14
- package/dist/src/io/EnvironmentDataObject.js +33 -29
- package/dist/src/io/EnvironmentDataStore.js +33 -29
- package/dist/src/io/EnvironmentDataStoreReference.js +35 -31
- package/dist/src/io/InputOutputSpecification.js +177 -168
- package/dist/src/io/Properties.js +117 -124
- package/dist/src/messageHelper.js +1 -1
- package/dist/src/process/Process.js +439 -362
- package/dist/src/process/ProcessExecution.js +748 -646
- package/dist/src/shared.js +2 -2
- package/dist/src/tasks/CallActivity.js +160 -0
- package/dist/src/tasks/LoopCharacteristics.js +309 -330
- package/dist/src/tasks/ReceiveTask.js +233 -182
- package/dist/src/tasks/ScriptTask.js +35 -41
- package/dist/src/tasks/ServiceImplementation.js +13 -20
- package/dist/src/tasks/ServiceTask.js +82 -75
- package/dist/src/tasks/SignalTask.js +97 -93
- package/dist/src/tasks/StandardLoopCharacteristics.js +1 -1
- package/dist/src/tasks/SubProcess.js +193 -175
- package/dist/src/tasks/Task.js +17 -19
- package/index.js +2 -0
- package/package.json +15 -15
- package/src/Api.js +65 -59
- package/src/Context.js +145 -140
- package/src/Environment.js +116 -100
- package/src/EventBroker.js +67 -68
- package/src/ExtensionsMapper.js +2 -2
- package/src/MessageFormatter.js +132 -74
- package/src/activity/Activity.js +915 -775
- package/src/activity/ActivityExecution.js +293 -247
- package/src/activity/Dummy.js +2 -2
- package/src/definition/Definition.js +437 -401
- package/src/definition/DefinitionExecution.js +598 -340
- package/src/error/Errors.js +11 -6
- package/src/eventDefinitions/CancelEventDefinition.js +164 -121
- package/src/eventDefinitions/CompensateEventDefinition.js +159 -124
- package/src/eventDefinitions/ConditionalEventDefinition.js +147 -104
- package/src/eventDefinitions/ErrorEventDefinition.js +190 -131
- package/src/eventDefinitions/EscalationEventDefinition.js +139 -101
- package/src/eventDefinitions/EventDefinitionExecution.js +127 -95
- package/src/eventDefinitions/LinkEventDefinition.js +160 -129
- package/src/eventDefinitions/MessageEventDefinition.js +178 -121
- package/src/eventDefinitions/SignalEventDefinition.js +162 -106
- package/src/eventDefinitions/TerminateEventDefinition.js +19 -19
- package/src/eventDefinitions/TimerEventDefinition.js +202 -167
- package/src/events/BoundaryEvent.js +156 -115
- package/src/events/EndEvent.js +15 -18
- package/src/events/IntermediateCatchEvent.js +40 -44
- package/src/events/IntermediateThrowEvent.js +15 -18
- package/src/events/StartEvent.js +84 -50
- package/src/flows/Association.js +98 -112
- package/src/flows/MessageFlow.js +81 -97
- package/src/flows/SequenceFlow.js +146 -160
- package/src/gateways/EventBasedGateway.js +75 -68
- package/src/gateways/ExclusiveGateway.js +8 -13
- package/src/gateways/InclusiveGateway.js +8 -13
- package/src/gateways/ParallelGateway.js +8 -13
- package/src/getPropertyValue.js +34 -33
- package/src/io/BpmnIO.js +20 -15
- package/src/io/EnvironmentDataObject.js +29 -18
- package/src/io/EnvironmentDataStore.js +29 -18
- package/src/io/EnvironmentDataStoreReference.js +31 -20
- package/src/io/InputOutputSpecification.js +154 -157
- package/src/io/Properties.js +95 -97
- package/src/process/Process.js +378 -333
- package/src/process/ProcessExecution.js +603 -553
- package/src/tasks/CallActivity.js +130 -0
- package/src/tasks/LoopCharacteristics.js +290 -289
- package/src/tasks/ReceiveTask.js +174 -107
- package/src/tasks/ScriptTask.js +27 -30
- package/src/tasks/ServiceImplementation.js +13 -18
- package/src/tasks/ServiceTask.js +67 -60
- package/src/tasks/SignalTask.js +77 -52
- package/src/tasks/StandardLoopCharacteristics.js +1 -1
- package/src/tasks/SubProcess.js +184 -157
- package/src/tasks/Task.js +15 -19
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.default = void 0;
|
|
7
7
|
|
|
8
8
|
var _ActivityExecution = _interopRequireDefault(require("./ActivityExecution"));
|
|
9
9
|
|
|
@@ -23,35 +23,49 @@ var _Errors = require("../error/Errors");
|
|
|
23
23
|
|
|
24
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
25
|
|
|
26
|
+
const kActivityDef = Symbol.for('activityDefinition');
|
|
27
|
+
const kBpmnIo = Symbol.for('bpmnIo');
|
|
28
|
+
const kConsuming = Symbol.for('consuming');
|
|
29
|
+
const kCounters = Symbol.for('counters');
|
|
30
|
+
const kEventDefinitions = Symbol.for('eventDefinitions');
|
|
31
|
+
const kExec = Symbol.for('exec');
|
|
32
|
+
const kExecuteMessage = Symbol.for('executeMessage');
|
|
33
|
+
const kExtensions = Symbol.for('extensions');
|
|
34
|
+
const kFlags = Symbol.for('flags');
|
|
35
|
+
const kFlows = Symbol.for('flows');
|
|
36
|
+
const kFormatter = Symbol.for('formatter');
|
|
37
|
+
const kMessageHandlers = Symbol.for('messageHandlers');
|
|
38
|
+
const kStateMessage = Symbol.for('stateMessage');
|
|
39
|
+
var _default = Activity;
|
|
40
|
+
exports.default = _default;
|
|
41
|
+
|
|
26
42
|
function Activity(Behaviour, activityDef, context) {
|
|
27
43
|
const {
|
|
28
44
|
id,
|
|
29
45
|
type = 'activity',
|
|
30
46
|
name,
|
|
31
|
-
|
|
32
|
-
behaviour = {},
|
|
33
|
-
isParallelGateway,
|
|
34
|
-
isSubProcess,
|
|
35
|
-
triggeredByEvent,
|
|
36
|
-
isThrowing,
|
|
37
|
-
isTransaction
|
|
47
|
+
behaviour = {}
|
|
38
48
|
} = activityDef;
|
|
39
|
-
const isForCompensation = behaviour.isForCompensation;
|
|
40
|
-
const parent = (0, _messageHelper.cloneParent)(originalParent);
|
|
41
|
-
const {
|
|
42
|
-
environment,
|
|
43
|
-
getInboundSequenceFlows,
|
|
44
|
-
getOutboundSequenceFlows,
|
|
45
|
-
getInboundAssociations
|
|
46
|
-
} = context;
|
|
47
|
-
const logger = environment.Logger(type.toLowerCase());
|
|
48
|
-
const {
|
|
49
|
-
step
|
|
50
|
-
} = environment.settings;
|
|
51
49
|
const {
|
|
52
50
|
attachedTo: attachedToRef,
|
|
53
51
|
eventDefinitions
|
|
54
52
|
} = behaviour;
|
|
53
|
+
this[kActivityDef] = activityDef;
|
|
54
|
+
this.id = id;
|
|
55
|
+
this.type = type;
|
|
56
|
+
this.name = name;
|
|
57
|
+
this.behaviour = { ...behaviour,
|
|
58
|
+
eventDefinitions
|
|
59
|
+
};
|
|
60
|
+
this.Behaviour = Behaviour;
|
|
61
|
+
this.parent = activityDef.parent ? (0, _messageHelper.cloneParent)(activityDef.parent) : {};
|
|
62
|
+
this.logger = context.environment.Logger(type.toLowerCase());
|
|
63
|
+
this.environment = context.environment;
|
|
64
|
+
this.context = context;
|
|
65
|
+
this[kCounters] = {
|
|
66
|
+
taken: 0,
|
|
67
|
+
discarded: 0
|
|
68
|
+
};
|
|
55
69
|
let attachedToActivity, attachedTo;
|
|
56
70
|
|
|
57
71
|
if (attachedToRef) {
|
|
@@ -59,118 +73,67 @@ function Activity(Behaviour, activityDef, context) {
|
|
|
59
73
|
attachedToActivity = context.getActivityById(attachedToRef.id);
|
|
60
74
|
}
|
|
61
75
|
|
|
62
|
-
const inboundSequenceFlows = getInboundSequenceFlows(id) || [];
|
|
63
|
-
const outboundSequenceFlows = getOutboundSequenceFlows(id) || [];
|
|
64
|
-
const inboundAssociations = getInboundAssociations(id) || [];
|
|
65
|
-
const isStart = inboundSequenceFlows.length === 0 && !attachedTo && !triggeredByEvent && !isForCompensation;
|
|
66
|
-
const isEnd = outboundSequenceFlows.length === 0;
|
|
67
|
-
const isParallelJoin = inboundSequenceFlows.length > 1 && isParallelGateway;
|
|
68
|
-
const isMultiInstance = !!behaviour.loopCharacteristics;
|
|
69
|
-
let execution,
|
|
70
|
-
initExecutionId,
|
|
71
|
-
executionId,
|
|
72
|
-
stateMessage,
|
|
73
|
-
status,
|
|
74
|
-
stopped = false,
|
|
75
|
-
executeMessage,
|
|
76
|
-
consumingRunQ;
|
|
77
|
-
const inboundTriggers = attachedToActivity ? [attachedToActivity] : inboundSequenceFlows.slice();
|
|
78
|
-
const inboundJoinFlows = [];
|
|
79
|
-
let counters = {
|
|
80
|
-
taken: 0,
|
|
81
|
-
discarded: 0
|
|
82
|
-
};
|
|
83
|
-
const activityApi = {
|
|
84
|
-
id,
|
|
85
|
-
type,
|
|
86
|
-
name,
|
|
87
|
-
isEnd,
|
|
88
|
-
isStart,
|
|
89
|
-
isSubProcess,
|
|
90
|
-
isThrowing,
|
|
91
|
-
isForCompensation,
|
|
92
|
-
triggeredByEvent,
|
|
93
|
-
parent: (0, _messageHelper.cloneParent)(parent),
|
|
94
|
-
behaviour: { ...behaviour,
|
|
95
|
-
eventDefinitions
|
|
96
|
-
},
|
|
97
|
-
attachedTo: attachedToActivity,
|
|
98
|
-
environment,
|
|
99
|
-
inbound: inboundSequenceFlows,
|
|
100
|
-
outbound: outboundSequenceFlows,
|
|
101
|
-
|
|
102
|
-
get counters() {
|
|
103
|
-
return { ...counters
|
|
104
|
-
};
|
|
105
|
-
},
|
|
106
|
-
|
|
107
|
-
get executionId() {
|
|
108
|
-
return executionId;
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
get status() {
|
|
112
|
-
return status;
|
|
113
|
-
},
|
|
114
|
-
|
|
115
|
-
get stopped() {
|
|
116
|
-
return stopped;
|
|
117
|
-
},
|
|
118
|
-
|
|
119
|
-
get isRunning() {
|
|
120
|
-
if (!consumingRunQ) return false;
|
|
121
|
-
return !!status;
|
|
122
|
-
},
|
|
123
|
-
|
|
124
|
-
Behaviour,
|
|
125
|
-
activate,
|
|
126
|
-
deactivate,
|
|
127
|
-
evaluateOutbound,
|
|
128
|
-
logger,
|
|
129
|
-
discard,
|
|
130
|
-
getApi,
|
|
131
|
-
getActivityById,
|
|
132
|
-
getState,
|
|
133
|
-
init,
|
|
134
|
-
recover,
|
|
135
|
-
resume,
|
|
136
|
-
run,
|
|
137
|
-
shake,
|
|
138
|
-
stop,
|
|
139
|
-
next: step && next
|
|
140
|
-
};
|
|
141
76
|
const {
|
|
142
77
|
broker,
|
|
143
78
|
on,
|
|
144
79
|
once,
|
|
145
80
|
waitFor,
|
|
146
81
|
emitFatal
|
|
147
|
-
} = (0, _EventBroker.ActivityBroker)(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
const
|
|
82
|
+
} = (0, _EventBroker.ActivityBroker)(this);
|
|
83
|
+
this.broker = broker;
|
|
84
|
+
this.on = on;
|
|
85
|
+
this.once = once;
|
|
86
|
+
this.waitFor = waitFor;
|
|
87
|
+
this.emitFatal = emitFatal;
|
|
88
|
+
const inboundSequenceFlows = context.getInboundSequenceFlows(id);
|
|
89
|
+
const inboundAssociations = context.getInboundAssociations(id);
|
|
90
|
+
const inboundTriggers = attachedToActivity ? [attachedToActivity] : inboundSequenceFlows.slice();
|
|
91
|
+
const outboundSequenceFlows = context.getOutboundSequenceFlows(id);
|
|
92
|
+
const flows = this[kFlows] = {
|
|
93
|
+
inboundSequenceFlows,
|
|
94
|
+
inboundAssociations,
|
|
95
|
+
inboundJoinFlows: [],
|
|
96
|
+
inboundTriggers,
|
|
97
|
+
outboundSequenceFlows,
|
|
98
|
+
outboundEvaluator: new OutboundEvaluator(this, outboundSequenceFlows)
|
|
99
|
+
};
|
|
100
|
+
const isForCompensation = !!behaviour.isForCompensation;
|
|
101
|
+
const isParallelJoin = activityDef.isParallelGateway && flows.inboundSequenceFlows.length > 1;
|
|
102
|
+
this[kFlags] = {
|
|
103
|
+
isEnd: flows.outboundSequenceFlows.length === 0,
|
|
104
|
+
isStart: flows.inboundSequenceFlows.length === 0 && !attachedTo && !behaviour.triggeredByEvent && !isForCompensation,
|
|
105
|
+
isSubProcess: activityDef.isSubProcess,
|
|
106
|
+
isMultiInstance: !!behaviour.loopCharacteristics,
|
|
107
|
+
isForCompensation,
|
|
108
|
+
attachedTo,
|
|
109
|
+
isTransaction: activityDef.isTransaction,
|
|
110
|
+
isParallelJoin,
|
|
111
|
+
isThrowing: activityDef.isThrowing
|
|
112
|
+
};
|
|
113
|
+
this[kExec] = {};
|
|
114
|
+
this[kMessageHandlers] = {
|
|
115
|
+
onInbound: isParallelJoin ? this._onJoinInbound.bind(this) : this._onInbound.bind(this),
|
|
116
|
+
onRunMessage: this._onRunMessage.bind(this),
|
|
117
|
+
onApiMessage: this._onApiMessage.bind(this),
|
|
118
|
+
onExecutionMessage: this._onExecutionMessage.bind(this)
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const onInboundEvent = this._onInboundEvent.bind(this);
|
|
122
|
+
|
|
123
|
+
broker.assertQueue('inbound-q', {
|
|
155
124
|
durable: true,
|
|
156
125
|
autoDelete: false
|
|
157
126
|
});
|
|
158
|
-
const formatRunQ = broker.getQueue('format-run-q');
|
|
159
|
-
const formatter = (0, _MessageFormatter.Formatter)({
|
|
160
|
-
id,
|
|
161
|
-
broker,
|
|
162
|
-
logger
|
|
163
|
-
}, formatRunQ);
|
|
164
127
|
|
|
165
128
|
if (isForCompensation) {
|
|
166
|
-
|
|
129
|
+
for (const trigger of inboundAssociations) {
|
|
167
130
|
trigger.broker.subscribeTmp('event', '#', onInboundEvent, {
|
|
168
131
|
noAck: true,
|
|
169
132
|
consumerTag: `_inbound-${id}`
|
|
170
133
|
});
|
|
171
|
-
}
|
|
134
|
+
}
|
|
172
135
|
} else {
|
|
173
|
-
|
|
136
|
+
for (const trigger of inboundTriggers) {
|
|
174
137
|
if (trigger.isSequenceFlow) trigger.broker.subscribeTmp('event', 'flow.#', onInboundEvent, {
|
|
175
138
|
noAck: true,
|
|
176
139
|
consumerTag: `_inbound-${id}`
|
|
@@ -178,969 +141,1196 @@ function Activity(Behaviour, activityDef, context) {
|
|
|
178
141
|
noAck: true,
|
|
179
142
|
consumerTag: `_inbound-${id}`
|
|
180
143
|
});
|
|
181
|
-
}
|
|
144
|
+
}
|
|
182
145
|
}
|
|
183
146
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
get: () => broker
|
|
187
|
-
});
|
|
188
|
-
Object.defineProperty(activityApi, 'execution', {
|
|
189
|
-
enumerable: true,
|
|
190
|
-
get: () => execution
|
|
191
|
-
});
|
|
192
|
-
const bpmnIo = (0, _BpmnIO.default)(activityApi, context);
|
|
193
|
-
const loaedEventDefinitions = eventDefinitions && eventDefinitions.map(ed => ed.Behaviour(activityApi, ed, context));
|
|
194
|
-
Object.defineProperty(activityApi, 'eventDefinitions', {
|
|
195
|
-
enumerable: true,
|
|
196
|
-
get: () => loaedEventDefinitions
|
|
197
|
-
});
|
|
198
|
-
const extensions = context.loadExtensions(activityApi);
|
|
199
|
-
Object.defineProperty(activityApi, 'extensions', {
|
|
200
|
-
enumerable: true,
|
|
201
|
-
get: () => extensions
|
|
202
|
-
});
|
|
203
|
-
return activityApi;
|
|
147
|
+
this[kEventDefinitions] = eventDefinitions && eventDefinitions.map(ed => new ed.Behaviour(this, ed, this.context));
|
|
148
|
+
}
|
|
204
149
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
150
|
+
const proto = Activity.prototype;
|
|
151
|
+
Object.defineProperty(proto, 'counters', {
|
|
152
|
+
enumerable: true,
|
|
153
|
+
|
|
154
|
+
get() {
|
|
155
|
+
return { ...this[kCounters]
|
|
156
|
+
};
|
|
211
157
|
}
|
|
212
158
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
executionId
|
|
220
|
-
});
|
|
221
|
-
broker.publish('run', 'run.enter', content);
|
|
222
|
-
broker.publish('run', 'run.start', (0, _messageHelper.cloneContent)(content));
|
|
223
|
-
consumeRunQ();
|
|
159
|
+
});
|
|
160
|
+
Object.defineProperty(proto, 'execution', {
|
|
161
|
+
enumerable: true,
|
|
162
|
+
|
|
163
|
+
get() {
|
|
164
|
+
return this[kExec].execution;
|
|
224
165
|
}
|
|
225
166
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
type,
|
|
230
|
-
...(name ? {
|
|
231
|
-
name
|
|
232
|
-
} : undefined),
|
|
233
|
-
...(status ? {
|
|
234
|
-
status
|
|
235
|
-
} : undefined),
|
|
236
|
-
parent: (0, _messageHelper.cloneParent)(parent)
|
|
237
|
-
};
|
|
238
|
-
const flags = {
|
|
239
|
-
isEnd,
|
|
240
|
-
isStart,
|
|
241
|
-
isSubProcess,
|
|
242
|
-
isMultiInstance,
|
|
243
|
-
isForCompensation,
|
|
244
|
-
attachedTo,
|
|
245
|
-
isTransaction
|
|
246
|
-
};
|
|
167
|
+
});
|
|
168
|
+
Object.defineProperty(proto, 'executionId', {
|
|
169
|
+
enumerable: true,
|
|
247
170
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
171
|
+
get() {
|
|
172
|
+
return this[kExec].executionId;
|
|
173
|
+
}
|
|
251
174
|
|
|
252
|
-
|
|
175
|
+
});
|
|
176
|
+
Object.defineProperty(proto, 'bpmnIo', {
|
|
177
|
+
enumerable: true,
|
|
178
|
+
|
|
179
|
+
get() {
|
|
180
|
+
if (kBpmnIo in this) return this[kBpmnIo];
|
|
181
|
+
const bpmnIo = this[kBpmnIo] = new _BpmnIO.default(this, this.context);
|
|
182
|
+
return bpmnIo;
|
|
253
183
|
}
|
|
254
184
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
stopped = state.stopped;
|
|
259
|
-
status = state.status;
|
|
260
|
-
executionId = state.executionId;
|
|
261
|
-
counters = { ...counters,
|
|
262
|
-
...state.counters
|
|
263
|
-
};
|
|
185
|
+
});
|
|
186
|
+
Object.defineProperty(proto, 'extensions', {
|
|
187
|
+
enumerable: true,
|
|
264
188
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
189
|
+
get() {
|
|
190
|
+
if (kExtensions in this) return this[kExtensions];
|
|
191
|
+
const extensions = this[kExtensions] = this.context.loadExtensions(this);
|
|
192
|
+
return extensions;
|
|
193
|
+
}
|
|
268
194
|
|
|
269
|
-
|
|
270
|
-
|
|
195
|
+
});
|
|
196
|
+
Object.defineProperty(proto, 'formatter', {
|
|
197
|
+
enumerable: true,
|
|
198
|
+
|
|
199
|
+
get() {
|
|
200
|
+
let formatter = this[kFormatter];
|
|
201
|
+
if (formatter) return formatter;
|
|
202
|
+
const broker = this.broker;
|
|
203
|
+
formatter = this[kFormatter] = new _MessageFormatter.Formatter({
|
|
204
|
+
id: this.id,
|
|
205
|
+
broker,
|
|
206
|
+
logger: this.logger
|
|
207
|
+
}, broker.getQueue('format-run-q'));
|
|
208
|
+
return formatter;
|
|
271
209
|
}
|
|
272
210
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
211
|
+
});
|
|
212
|
+
Object.defineProperty(proto, 'isRunning', {
|
|
213
|
+
enumerable: true,
|
|
277
214
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const content = createMessage({
|
|
282
|
-
executionId
|
|
283
|
-
});
|
|
284
|
-
broker.publish('run', 'run.resume', content, {
|
|
285
|
-
persistent: false
|
|
286
|
-
});
|
|
287
|
-
consumeRunQ();
|
|
215
|
+
get() {
|
|
216
|
+
if (!this[kConsuming]) return false;
|
|
217
|
+
return !!this.status;
|
|
288
218
|
}
|
|
289
219
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
consumeRunQ();
|
|
220
|
+
});
|
|
221
|
+
Object.defineProperty(proto, 'outbound', {
|
|
222
|
+
enumerable: true,
|
|
223
|
+
|
|
224
|
+
get() {
|
|
225
|
+
return this[kFlows].outboundSequenceFlows;
|
|
297
226
|
}
|
|
298
227
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
228
|
+
});
|
|
229
|
+
Object.defineProperty(proto, 'inbound', {
|
|
230
|
+
enumerable: true,
|
|
231
|
+
|
|
232
|
+
get() {
|
|
233
|
+
return this[kFlows].inboundSequenceFlows;
|
|
234
|
+
}
|
|
302
235
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
case 'discarded':
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
236
|
+
});
|
|
237
|
+
Object.defineProperty(proto, 'isEnd', {
|
|
238
|
+
enumerable: true,
|
|
309
239
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
runQ.purge();
|
|
313
|
-
broker.publish('run', 'run.discard', (0, _messageHelper.cloneContent)(stateMessage.content));
|
|
314
|
-
consumeRunQ();
|
|
240
|
+
get() {
|
|
241
|
+
return this[kFlags].isEnd;
|
|
315
242
|
}
|
|
316
243
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
});
|
|
324
|
-
broker.publish('run', 'run.discard', content);
|
|
325
|
-
consumeRunQ();
|
|
244
|
+
});
|
|
245
|
+
Object.defineProperty(proto, 'isStart', {
|
|
246
|
+
enumerable: true,
|
|
247
|
+
|
|
248
|
+
get() {
|
|
249
|
+
return this[kFlags].isStart;
|
|
326
250
|
}
|
|
327
251
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
252
|
+
});
|
|
253
|
+
Object.defineProperty(proto, 'isSubProcess', {
|
|
254
|
+
enumerable: true,
|
|
255
|
+
|
|
256
|
+
get() {
|
|
257
|
+
return this[kFlags].isSubProcess;
|
|
331
258
|
}
|
|
332
259
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
broker.cancel('_activity-execution');
|
|
340
|
-
broker.cancel('_run-on-inbound');
|
|
341
|
-
broker.cancel('_format-consumer');
|
|
342
|
-
|
|
343
|
-
if (running) {
|
|
344
|
-
if (extensions) extensions.deactivate(message || createMessage());
|
|
345
|
-
publishEvent('stop');
|
|
346
|
-
}
|
|
260
|
+
});
|
|
261
|
+
Object.defineProperty(proto, 'isMultiInstance', {
|
|
262
|
+
enumerable: true,
|
|
263
|
+
|
|
264
|
+
get() {
|
|
265
|
+
return this[kFlags].isMultiInstance;
|
|
347
266
|
}
|
|
348
267
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
268
|
+
});
|
|
269
|
+
Object.defineProperty(proto, 'isThrowing', {
|
|
270
|
+
enumerable: true,
|
|
271
|
+
|
|
272
|
+
get() {
|
|
273
|
+
return this[kFlags].isThrowing;
|
|
352
274
|
}
|
|
353
275
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
276
|
+
});
|
|
277
|
+
Object.defineProperty(proto, 'isForCompensation', {
|
|
278
|
+
enumerable: true,
|
|
279
|
+
|
|
280
|
+
get() {
|
|
281
|
+
return this[kFlags].isForCompensation;
|
|
357
282
|
}
|
|
358
283
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
});
|
|
284
|
+
});
|
|
285
|
+
Object.defineProperty(proto, 'triggeredByEvent', {
|
|
286
|
+
enumerable: true,
|
|
287
|
+
|
|
288
|
+
get() {
|
|
289
|
+
return this[kActivityDef].triggeredByEvent;
|
|
366
290
|
}
|
|
367
291
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
292
|
+
});
|
|
293
|
+
Object.defineProperty(proto, 'attachedTo', {
|
|
294
|
+
enumerable: true,
|
|
295
|
+
|
|
296
|
+
get() {
|
|
297
|
+
const attachedToId = this[kFlags].attachedTo;
|
|
298
|
+
if (!attachedToId) return null;
|
|
299
|
+
return this.getActivityById(attachedToId);
|
|
376
300
|
}
|
|
377
301
|
|
|
378
|
-
|
|
379
|
-
|
|
302
|
+
});
|
|
303
|
+
Object.defineProperty(proto, 'eventDefinitions', {
|
|
304
|
+
enumerable: true,
|
|
380
305
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
prefetch: 1000
|
|
385
|
-
});
|
|
386
|
-
}
|
|
306
|
+
get() {
|
|
307
|
+
return this[kEventDefinitions];
|
|
308
|
+
}
|
|
387
309
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
proto.activate = function activate() {
|
|
313
|
+
if (this[kFlags].isForCompensation) return;
|
|
314
|
+
return this._consumeInbound();
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
proto.deactivate = function deactivate() {
|
|
318
|
+
const broker = this.broker;
|
|
319
|
+
broker.cancel('_run-on-inbound');
|
|
320
|
+
broker.cancel('_format-consumer');
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
proto.init = function init(initContent) {
|
|
324
|
+
const id = this.id;
|
|
325
|
+
const exec = this[kExec];
|
|
326
|
+
const executionId = exec.initExecutionId = exec.initExecutionId || (0, _shared.getUniqueId)(id);
|
|
327
|
+
this.logger.debug(`<${id}> initialized with executionId <${executionId}>`);
|
|
328
|
+
|
|
329
|
+
this._publishEvent('init', this._createMessage({ ...initContent,
|
|
330
|
+
executionId
|
|
331
|
+
}));
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
proto.run = function run(runContent) {
|
|
335
|
+
const id = this.id;
|
|
336
|
+
if (this.isRunning) throw new Error(`activity <${id}> is already running`);
|
|
337
|
+
const exec = this[kExec];
|
|
338
|
+
const executionId = exec.executionId = exec.initExecutionId || (0, _shared.getUniqueId)(id);
|
|
339
|
+
exec.initExecutionId = null;
|
|
340
|
+
|
|
341
|
+
this._consumeApi();
|
|
342
|
+
|
|
343
|
+
const content = this._createMessage({ ...runContent,
|
|
344
|
+
executionId
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
const broker = this.broker;
|
|
348
|
+
broker.publish('run', 'run.enter', content);
|
|
349
|
+
broker.publish('run', 'run.start', (0, _messageHelper.cloneContent)(content));
|
|
350
|
+
|
|
351
|
+
this._consumeRunQ();
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
proto.recover = function recover(state) {
|
|
355
|
+
if (this.isRunning) throw new Error(`cannot recover running activity <${this.id}>`);
|
|
356
|
+
if (!state) return;
|
|
357
|
+
this.stopped = state.stopped;
|
|
358
|
+
this.status = state.status;
|
|
359
|
+
const exec = this[kExec];
|
|
360
|
+
exec.executionId = state.executionId;
|
|
361
|
+
this[kCounters] = { ...this[kCounters],
|
|
362
|
+
...state.counters
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
if (state.execution) {
|
|
366
|
+
exec.execution = new _ActivityExecution.default(this, this.context).recover(state.execution);
|
|
391
367
|
}
|
|
392
368
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
369
|
+
this.broker.recover(state.broker);
|
|
370
|
+
return this;
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
proto.resume = function resume() {
|
|
374
|
+
if (this[kConsuming]) {
|
|
375
|
+
throw new Error(`cannot resume running activity <${this.id}>`);
|
|
398
376
|
}
|
|
399
377
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
fields,
|
|
403
|
-
content,
|
|
404
|
-
properties
|
|
405
|
-
} = message;
|
|
406
|
-
|
|
407
|
-
switch (routingKey) {
|
|
408
|
-
case 'activity.enter':
|
|
409
|
-
case 'activity.discard':
|
|
410
|
-
{
|
|
411
|
-
if (content.id === attachedToActivity.id) {
|
|
412
|
-
inboundQ.queueMessage(fields, (0, _messageHelper.cloneContent)(content), properties);
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
break;
|
|
416
|
-
}
|
|
378
|
+
if (!this.status) return this.activate();
|
|
379
|
+
this.stopped = false;
|
|
417
380
|
|
|
418
|
-
|
|
419
|
-
{
|
|
420
|
-
shakeOutbound(message);
|
|
421
|
-
break;
|
|
422
|
-
}
|
|
381
|
+
this._consumeApi();
|
|
423
382
|
|
|
424
|
-
|
|
425
|
-
case 'flow.take':
|
|
426
|
-
case 'flow.discard':
|
|
427
|
-
inboundQ.queueMessage(fields, (0, _messageHelper.cloneContent)(content), properties);
|
|
428
|
-
break;
|
|
383
|
+
const content = this._createMessage();
|
|
429
384
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
inboundQ.purge();
|
|
434
|
-
break;
|
|
435
|
-
}
|
|
385
|
+
this.broker.publish('run', 'run.resume', content, {
|
|
386
|
+
persistent: false
|
|
387
|
+
});
|
|
436
388
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
389
|
+
this._consumeRunQ();
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
proto.discard = function discard(discardContent) {
|
|
393
|
+
if (!this.status) return this._runDiscard(discardContent);
|
|
394
|
+
const execution = this[kExec].execution;
|
|
395
|
+
if (execution && !execution.completed) return execution.discard();
|
|
396
|
+
|
|
397
|
+
this._deactivateRunConsumers();
|
|
398
|
+
|
|
399
|
+
const broker = this.broker;
|
|
400
|
+
broker.getQueue('run-q').purge();
|
|
401
|
+
broker.publish('run', 'run.discard', (0, _messageHelper.cloneContent)(this[kStateMessage].content));
|
|
402
|
+
|
|
403
|
+
this._consumeRunQ();
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
proto.stop = function stop() {
|
|
407
|
+
if (!this[kConsuming]) return;
|
|
408
|
+
return this.getApi().stop();
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
proto.next = function next() {
|
|
412
|
+
if (!this.environment.settings.step) return;
|
|
413
|
+
const stateMessage = this[kStateMessage];
|
|
414
|
+
if (!stateMessage) return;
|
|
415
|
+
if (this.status === 'executing') return false;
|
|
416
|
+
if (this.status === 'formatting') return false;
|
|
417
|
+
const current = stateMessage;
|
|
418
|
+
stateMessage.ack();
|
|
419
|
+
return current;
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
proto.shake = function shake() {
|
|
423
|
+
this._shakeOutbound({
|
|
424
|
+
content: this._createMessage()
|
|
425
|
+
});
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
proto.evaluateOutbound = function evaluateOutbound(fromMessage, discardRestAtTake, callback) {
|
|
429
|
+
return this[kFlows].outboundEvaluator.evaluate(fromMessage, discardRestAtTake, callback);
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
proto.getState = function getState() {
|
|
433
|
+
const msg = this._createMessage();
|
|
434
|
+
|
|
435
|
+
const exec = this[kExec];
|
|
436
|
+
return { ...msg,
|
|
437
|
+
executionId: exec.executionId,
|
|
438
|
+
stopped: this.stopped,
|
|
439
|
+
behaviour: { ...this.behaviour
|
|
440
|
+
},
|
|
441
|
+
counters: this.counters,
|
|
442
|
+
broker: this.broker.getState(true),
|
|
443
|
+
execution: exec.execution && exec.execution.getState()
|
|
444
|
+
};
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
proto.getApi = function getApi(message) {
|
|
448
|
+
const execution = this[kExec].execution;
|
|
449
|
+
if (execution && !execution.completed) return execution.getApi(message);
|
|
450
|
+
return (0, _Api.ActivityApi)(this.broker, message || this[kStateMessage]);
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
proto.getActivityById = function getActivityById(elementId) {
|
|
454
|
+
return this.context.getActivityById(elementId);
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
proto._runDiscard = function runDiscard(discardContent) {
|
|
458
|
+
const exec = this[kExec];
|
|
459
|
+
const executionId = exec.executionId = exec.initExecutionId || (0, _shared.getUniqueId)(this.id);
|
|
460
|
+
exec.initExecutionId = null;
|
|
461
|
+
|
|
462
|
+
this._consumeApi();
|
|
463
|
+
|
|
464
|
+
const content = this._createMessage({ ...discardContent,
|
|
465
|
+
executionId
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
this.broker.publish('run', 'run.discard', content);
|
|
469
|
+
|
|
470
|
+
this._consumeRunQ();
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
proto._discardRun = function discardRun() {
|
|
474
|
+
const status = this.status;
|
|
475
|
+
if (!status) return;
|
|
476
|
+
const execution = this[kExec].execution;
|
|
477
|
+
if (execution && !execution.completed) return;
|
|
478
|
+
|
|
479
|
+
switch (status) {
|
|
480
|
+
case 'executing':
|
|
481
|
+
case 'error':
|
|
482
|
+
case 'discarded':
|
|
483
|
+
return;
|
|
451
484
|
}
|
|
452
485
|
|
|
453
|
-
|
|
454
|
-
message.ack();
|
|
455
|
-
broker.cancel('_run-on-inbound');
|
|
456
|
-
const content = message.content;
|
|
457
|
-
const inbound = [(0, _messageHelper.cloneContent)(content)];
|
|
458
|
-
|
|
459
|
-
switch (routingKey) {
|
|
460
|
-
case 'association.take':
|
|
461
|
-
case 'flow.take':
|
|
462
|
-
case 'activity.enter':
|
|
463
|
-
run({
|
|
464
|
-
message: content.message,
|
|
465
|
-
inbound
|
|
466
|
-
});
|
|
467
|
-
break;
|
|
486
|
+
this._deactivateRunConsumers();
|
|
468
487
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
if (content.discardSequence) discardSequence = content.discardSequence.slice();
|
|
474
|
-
runDiscard({
|
|
475
|
-
inbound,
|
|
476
|
-
discardSequence
|
|
477
|
-
});
|
|
478
|
-
break;
|
|
479
|
-
}
|
|
488
|
+
if (this.extensions) this.extensions.deactivate();
|
|
489
|
+
const broker = this.broker;
|
|
490
|
+
broker.getQueue('run-q').purge();
|
|
491
|
+
broker.publish('run', 'run.discard', (0, _messageHelper.cloneContent)(this[kStateMessage].content));
|
|
480
492
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
493
|
+
this._consumeRunQ();
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
proto._shakeOutbound = function shakeOutbound(sourceMessage) {
|
|
497
|
+
const message = (0, _messageHelper.cloneMessage)(sourceMessage);
|
|
498
|
+
message.content.sequence = message.content.sequence || [];
|
|
499
|
+
message.content.sequence.push({
|
|
500
|
+
id: this.id,
|
|
501
|
+
type: this.type
|
|
502
|
+
});
|
|
503
|
+
const broker = this.broker;
|
|
504
|
+
this.broker.publish('api', 'activity.shake.start', message.content, {
|
|
505
|
+
persistent: false,
|
|
506
|
+
type: 'shake'
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
if (this[kFlags].isEnd) {
|
|
510
|
+
return broker.publish('event', 'activity.shake.end', message.content, {
|
|
511
|
+
persistent: false,
|
|
512
|
+
type: 'shake'
|
|
513
|
+
});
|
|
492
514
|
}
|
|
493
515
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
if (idx > -1) return;
|
|
501
|
-
const allTouched = inboundJoinFlows.length >= inboundTriggers.length;
|
|
502
|
-
|
|
503
|
-
if (!allTouched) {
|
|
504
|
-
const remaining = inboundSequenceFlows.filter((inb, i, list) => list.indexOf(inb) === i).length - inboundJoinFlows.length;
|
|
505
|
-
return logger.debug(`<${id}> inbound ${message.content.action} from <${message.content.id}>, ${remaining} remaining`);
|
|
506
|
-
}
|
|
516
|
+
for (const flow of this[kFlows].outboundSequenceFlows) flow.shake(message);
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
proto._consumeInbound = function consumeInbound() {
|
|
520
|
+
if (this.status) return;
|
|
521
|
+
const inboundQ = this.broker.getQueue('inbound-q');
|
|
507
522
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
im.ack();
|
|
513
|
-
return (0, _messageHelper.cloneContent)(im.content);
|
|
523
|
+
if (this[kFlags].isParallelJoin) {
|
|
524
|
+
return inboundQ.consume(this[kMessageHandlers].onInbound, {
|
|
525
|
+
consumerTag: '_run-on-inbound',
|
|
526
|
+
prefetch: 1000
|
|
514
527
|
});
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
return inboundQ.consume(this[kMessageHandlers].onInbound, {
|
|
531
|
+
consumerTag: '_run-on-inbound'
|
|
532
|
+
});
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
proto._onInbound = function onInbound(routingKey, message) {
|
|
536
|
+
message.ack();
|
|
537
|
+
const id = this.id;
|
|
538
|
+
const broker = this.broker;
|
|
539
|
+
broker.cancel('_run-on-inbound');
|
|
540
|
+
const content = message.content;
|
|
541
|
+
const inbound = [(0, _messageHelper.cloneContent)(content)];
|
|
542
|
+
|
|
543
|
+
switch (routingKey) {
|
|
544
|
+
case 'association.take':
|
|
545
|
+
case 'flow.take':
|
|
546
|
+
case 'activity.enter':
|
|
547
|
+
return this.run({
|
|
548
|
+
message: content.message,
|
|
549
|
+
inbound
|
|
519
550
|
});
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
551
|
+
|
|
552
|
+
case 'flow.discard':
|
|
553
|
+
case 'activity.discard':
|
|
554
|
+
{
|
|
555
|
+
let discardSequence;
|
|
556
|
+
if (content.discardSequence) discardSequence = content.discardSequence.slice();
|
|
557
|
+
return this._runDiscard({
|
|
558
|
+
inbound,
|
|
559
|
+
discardSequence
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
case 'association.complete':
|
|
564
|
+
{
|
|
565
|
+
broker.cancel('_run-on-inbound');
|
|
566
|
+
const compensationId = `${(0, _shared.brokerSafeId)(id)}_${(0, _shared.brokerSafeId)(content.sequenceId)}`;
|
|
567
|
+
this.logger.debug(`<${id}> completed compensation with id <${compensationId}>`);
|
|
568
|
+
return this._publishEvent('compensation.end', this._createMessage({
|
|
569
|
+
executionId: compensationId
|
|
570
|
+
}));
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
|
|
575
|
+
proto._onJoinInbound = function onJoinInbound(routingKey, message) {
|
|
576
|
+
const {
|
|
577
|
+
content
|
|
578
|
+
} = message;
|
|
579
|
+
const {
|
|
580
|
+
inboundSequenceFlows,
|
|
581
|
+
inboundJoinFlows,
|
|
582
|
+
inboundTriggers
|
|
583
|
+
} = this[kFlows];
|
|
584
|
+
const idx = inboundJoinFlows.findIndex(msg => msg.content.id === content.id);
|
|
585
|
+
inboundJoinFlows.push(message);
|
|
586
|
+
if (idx > -1) return;
|
|
587
|
+
const allTouched = inboundJoinFlows.length >= inboundTriggers.length;
|
|
588
|
+
|
|
589
|
+
if (!allTouched) {
|
|
590
|
+
const remaining = inboundSequenceFlows.filter((inb, i, list) => list.indexOf(inb) === i).length - inboundJoinFlows.length;
|
|
591
|
+
return this.logger.debug(`<${this.id}> inbound ${message.content.action} from <${message.content.id}>, ${remaining} remaining`);
|
|
530
592
|
}
|
|
531
593
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
594
|
+
const evaluatedInbound = inboundJoinFlows.splice(0);
|
|
595
|
+
let taken;
|
|
596
|
+
const inbound = evaluatedInbound.map(im => {
|
|
597
|
+
if (im.fields.routingKey === 'flow.take') taken = true;
|
|
598
|
+
im.ack();
|
|
599
|
+
return (0, _messageHelper.cloneContent)(im.content);
|
|
600
|
+
});
|
|
601
|
+
const discardSequence = !taken && evaluatedInbound.reduce((result, im) => {
|
|
602
|
+
if (!im.content.discardSequence) return result;
|
|
538
603
|
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
return onResumeMessage();
|
|
542
|
-
}
|
|
604
|
+
for (const sourceId of im.content.discardSequence) {
|
|
605
|
+
if (result.indexOf(sourceId) === -1) result.push(sourceId);
|
|
543
606
|
}
|
|
544
607
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
608
|
+
return result;
|
|
609
|
+
}, []);
|
|
610
|
+
this.broker.cancel('_run-on-inbound');
|
|
611
|
+
if (!taken) return this._runDiscard({
|
|
612
|
+
inbound,
|
|
613
|
+
discardSequence
|
|
614
|
+
});
|
|
615
|
+
return this.run({
|
|
616
|
+
inbound
|
|
617
|
+
});
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
proto._onInboundEvent = function onInboundEvent(routingKey, message) {
|
|
621
|
+
const {
|
|
622
|
+
fields,
|
|
623
|
+
content,
|
|
624
|
+
properties
|
|
625
|
+
} = message;
|
|
626
|
+
const id = this.id;
|
|
627
|
+
const inboundQ = this.broker.getQueue('inbound-q');
|
|
628
|
+
|
|
629
|
+
switch (routingKey) {
|
|
630
|
+
case 'activity.enter':
|
|
631
|
+
case 'activity.discard':
|
|
632
|
+
{
|
|
633
|
+
if (content.id === this[kFlags].attachedTo) {
|
|
634
|
+
inboundQ.queueMessage(fields, (0, _messageHelper.cloneContent)(content), properties);
|
|
635
|
+
}
|
|
553
636
|
|
|
554
|
-
|
|
555
|
-
message.ack();
|
|
556
|
-
const {
|
|
557
|
-
fields
|
|
558
|
-
} = stateMessage;
|
|
559
|
-
|
|
560
|
-
switch (fields.routingKey) {
|
|
561
|
-
case 'run.enter':
|
|
562
|
-
case 'run.start':
|
|
563
|
-
case 'run.discarded':
|
|
564
|
-
case 'run.end':
|
|
565
|
-
case 'run.leave':
|
|
566
|
-
break;
|
|
567
|
-
|
|
568
|
-
default:
|
|
569
|
-
return;
|
|
637
|
+
break;
|
|
570
638
|
}
|
|
571
639
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
640
|
+
case 'flow.shake':
|
|
641
|
+
{
|
|
642
|
+
return this._shakeOutbound(message);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
case 'association.take':
|
|
646
|
+
case 'flow.take':
|
|
647
|
+
case 'flow.discard':
|
|
648
|
+
return inboundQ.queueMessage(fields, (0, _messageHelper.cloneContent)(content), properties);
|
|
649
|
+
|
|
650
|
+
case 'association.discard':
|
|
651
|
+
{
|
|
652
|
+
this.logger.debug(`<${id}> compensation discarded`);
|
|
653
|
+
return inboundQ.purge();
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
case 'association.complete':
|
|
657
|
+
{
|
|
658
|
+
if (!this[kFlags].isForCompensation) break;
|
|
659
|
+
inboundQ.queueMessage(fields, (0, _messageHelper.cloneContent)(content), properties);
|
|
660
|
+
const compensationId = `${(0, _shared.brokerSafeId)(id)}_${(0, _shared.brokerSafeId)(content.sequenceId)}`;
|
|
661
|
+
|
|
662
|
+
this._publishEvent('compensation.start', this._createMessage({
|
|
663
|
+
executionId: compensationId,
|
|
664
|
+
placeholder: true
|
|
665
|
+
}));
|
|
666
|
+
|
|
667
|
+
this.logger.debug(`<${id}> start compensation with id <${compensationId}>`);
|
|
668
|
+
return this._consumeInbound();
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
|
|
673
|
+
proto._consumeRunQ = function consumeRunQ() {
|
|
674
|
+
if (this[kConsuming]) return;
|
|
675
|
+
this[kConsuming] = true;
|
|
676
|
+
this.broker.getQueue('run-q').assertConsumer(this[kMessageHandlers].onRunMessage, {
|
|
677
|
+
exclusive: true,
|
|
678
|
+
consumerTag: '_activity-run'
|
|
679
|
+
});
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
proto._onRunMessage = function onRunMessage(routingKey, message, messageProperties) {
|
|
683
|
+
switch (routingKey) {
|
|
684
|
+
case 'run.outbound.discard':
|
|
685
|
+
case 'run.outbound.take':
|
|
686
|
+
case 'run.next':
|
|
687
|
+
return this._continueRunMessage(routingKey, message, messageProperties);
|
|
688
|
+
|
|
689
|
+
case 'run.resume':
|
|
690
|
+
{
|
|
691
|
+
return this._onResumeMessage(message);
|
|
692
|
+
}
|
|
576
693
|
}
|
|
577
694
|
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
const isRedelivered = fields.redelivered;
|
|
585
|
-
const content = (0, _messageHelper.cloneContent)(originalContent);
|
|
586
|
-
const {
|
|
587
|
-
correlationId
|
|
588
|
-
} = message.properties;
|
|
589
|
-
stateMessage = message;
|
|
590
|
-
|
|
591
|
-
switch (routingKey) {
|
|
592
|
-
case 'run.enter':
|
|
593
|
-
{
|
|
594
|
-
logger.debug(`<${id}> enter`, isRedelivered ? 'redelivered' : '');
|
|
595
|
-
status = 'entered';
|
|
596
|
-
|
|
597
|
-
if (!isRedelivered) {
|
|
598
|
-
execution = undefined;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
if (extensions) extensions.activate((0, _messageHelper.cloneMessage)(message), activityApi);
|
|
602
|
-
if (bpmnIo) bpmnIo.activate(message);
|
|
603
|
-
if (!isRedelivered) publishEvent('enter', content, {
|
|
604
|
-
correlationId
|
|
605
|
-
});
|
|
606
|
-
break;
|
|
607
|
-
}
|
|
695
|
+
const preStatus = this.status;
|
|
696
|
+
this.status = 'formatting';
|
|
697
|
+
return this.formatter.format(message, (err, formattedContent, formatted) => {
|
|
698
|
+
if (err) return this.emitFatal(err, message.content);
|
|
699
|
+
if (formatted) message.content = formattedContent;
|
|
700
|
+
this.status = preStatus;
|
|
608
701
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
702
|
+
this._continueRunMessage(routingKey, message, messageProperties);
|
|
703
|
+
});
|
|
704
|
+
};
|
|
705
|
+
|
|
706
|
+
proto._continueRunMessage = function continueRunMessage(routingKey, message) {
|
|
707
|
+
const isRedelivered = message.fields.redelivered;
|
|
708
|
+
const content = (0, _messageHelper.cloneContent)(message.content);
|
|
709
|
+
const correlationId = message.properties.correlationId;
|
|
710
|
+
const id = this.id;
|
|
711
|
+
const step = this.environment.settings.step;
|
|
712
|
+
this[kStateMessage] = message;
|
|
713
|
+
|
|
714
|
+
switch (routingKey) {
|
|
715
|
+
case 'run.enter':
|
|
716
|
+
{
|
|
717
|
+
this.logger.debug(`<${id}> enter`, isRedelivered ? 'redelivered' : '');
|
|
718
|
+
this.status = 'entered';
|
|
719
|
+
|
|
720
|
+
if (!isRedelivered) {
|
|
721
|
+
this[kExec].execution = null;
|
|
625
722
|
}
|
|
626
723
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
correlationId
|
|
635
|
-
});
|
|
636
|
-
publishEvent('start', content, {
|
|
637
|
-
correlationId
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
break;
|
|
642
|
-
}
|
|
724
|
+
if (this.extensions) this.extensions.activate((0, _messageHelper.cloneMessage)(message), this);
|
|
725
|
+
if (this.bpmnIo) this.bpmnIo.activate(message);
|
|
726
|
+
if (!isRedelivered) this._publishEvent('enter', content, {
|
|
727
|
+
correlationId
|
|
728
|
+
});
|
|
729
|
+
break;
|
|
730
|
+
}
|
|
643
731
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
732
|
+
case 'run.discard':
|
|
733
|
+
{
|
|
734
|
+
this.logger.debug(`<${id}> discard`, isRedelivered ? 'redelivered' : '');
|
|
735
|
+
this.status = 'discard';
|
|
736
|
+
this[kExec].execution = null;
|
|
737
|
+
if (this.extensions) this.extensions.activate((0, _messageHelper.cloneMessage)(message), this);
|
|
738
|
+
if (this.bpmnIo) this.bpmnIo.activate(message);
|
|
651
739
|
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
executeMessage = message;
|
|
656
|
-
executionQ.assertConsumer(onExecutionMessage, {
|
|
657
|
-
exclusive: true,
|
|
658
|
-
consumerTag: '_activity-execution'
|
|
740
|
+
if (!isRedelivered) {
|
|
741
|
+
this.broker.publish('run', 'run.discarded', content, {
|
|
742
|
+
correlationId
|
|
659
743
|
});
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
if (isRedelivered) {
|
|
663
|
-
return resumeExtensions(message, (err, formattedContent) => {
|
|
664
|
-
if (err) return emitFatal(err, message.content);
|
|
665
|
-
if (formattedContent) message.content = formattedContent;
|
|
666
|
-
status = 'executing';
|
|
667
|
-
return execution.execute(message);
|
|
668
|
-
});
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
return execution.execute(message);
|
|
744
|
+
|
|
745
|
+
this._publishEvent('discard', content);
|
|
672
746
|
}
|
|
673
747
|
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
748
|
+
break;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
case 'run.start':
|
|
752
|
+
{
|
|
753
|
+
this.logger.debug(`<${id}> start`, isRedelivered ? 'redelivered' : '');
|
|
754
|
+
this.status = 'started';
|
|
755
|
+
|
|
756
|
+
if (!isRedelivered) {
|
|
757
|
+
this.broker.publish('run', 'run.execute', content, {
|
|
758
|
+
correlationId
|
|
685
759
|
});
|
|
686
|
-
}
|
|
687
760
|
|
|
688
|
-
|
|
689
|
-
{
|
|
690
|
-
publishEvent('error', (0, _messageHelper.cloneContent)(content, {
|
|
691
|
-
error: fields.redelivered ? (0, _Errors.makeErrorFromMessage)(message) : content.error
|
|
692
|
-
}), {
|
|
761
|
+
this._publishEvent('start', content, {
|
|
693
762
|
correlationId
|
|
694
763
|
});
|
|
695
|
-
break;
|
|
696
764
|
}
|
|
697
765
|
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
logger.debug(`<${executionId} (${id})> discarded`);
|
|
701
|
-
counters.discarded++;
|
|
702
|
-
status = 'discarded';
|
|
703
|
-
content.outbound = undefined;
|
|
704
|
-
|
|
705
|
-
if (!isRedelivered) {
|
|
706
|
-
return doRunLeave(true, () => {
|
|
707
|
-
if (!step) ack();
|
|
708
|
-
});
|
|
709
|
-
}
|
|
766
|
+
break;
|
|
767
|
+
}
|
|
710
768
|
|
|
711
|
-
|
|
712
|
-
|
|
769
|
+
case 'run.execute.passthrough':
|
|
770
|
+
{
|
|
771
|
+
const execution = this.execution;
|
|
713
772
|
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
ack();
|
|
718
|
-
return flow.take(content.flow);
|
|
773
|
+
if (!isRedelivered && execution) {
|
|
774
|
+
this[kExecuteMessage] = message;
|
|
775
|
+
return execution.passthrough(message);
|
|
719
776
|
}
|
|
777
|
+
}
|
|
720
778
|
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
779
|
+
case 'run.execute':
|
|
780
|
+
{
|
|
781
|
+
this.status = 'executing';
|
|
782
|
+
this[kExecuteMessage] = message;
|
|
783
|
+
this.broker.getQueue('execution-q').assertConsumer(this[kMessageHandlers].onExecutionMessage, {
|
|
784
|
+
exclusive: true,
|
|
785
|
+
consumerTag: '_activity-execution'
|
|
786
|
+
});
|
|
787
|
+
const exec = this[kExec];
|
|
788
|
+
if (!exec.execution) exec.execution = new _ActivityExecution.default(this, this.context);
|
|
789
|
+
|
|
790
|
+
if (isRedelivered) {
|
|
791
|
+
return this._resumeExtensions(message, (err, formattedContent) => {
|
|
792
|
+
if (err) return this.emitFatal(err, message.content);
|
|
793
|
+
if (formattedContent) message.content = formattedContent;
|
|
794
|
+
this.status = 'executing';
|
|
795
|
+
return exec.execution.execute(message);
|
|
796
|
+
});
|
|
726
797
|
}
|
|
727
798
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
status = undefined;
|
|
731
|
-
if (bpmnIo) bpmnIo.deactivate(message);
|
|
732
|
-
if (extensions) extensions.deactivate(message);
|
|
733
|
-
|
|
734
|
-
if (!isRedelivered) {
|
|
735
|
-
broker.publish('run', 'run.next', (0, _messageHelper.cloneContent)(content), {
|
|
736
|
-
persistent: false
|
|
737
|
-
});
|
|
738
|
-
publishEvent('leave', content, {
|
|
739
|
-
correlationId
|
|
740
|
-
});
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
break;
|
|
744
|
-
}
|
|
799
|
+
return exec.execution.execute(message);
|
|
800
|
+
}
|
|
745
801
|
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
break;
|
|
749
|
-
|
|
802
|
+
case 'run.end':
|
|
803
|
+
{
|
|
804
|
+
if (this.status === 'end') break;
|
|
805
|
+
this[kCounters].taken++;
|
|
806
|
+
this.status = 'end';
|
|
807
|
+
if (isRedelivered) break;
|
|
808
|
+
return this._doRunLeave(message, false, () => {
|
|
809
|
+
this._publishEvent('end', content, {
|
|
810
|
+
correlationId
|
|
811
|
+
});
|
|
750
812
|
|
|
751
|
-
|
|
813
|
+
if (!step) message.ack();
|
|
814
|
+
});
|
|
815
|
+
}
|
|
752
816
|
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
817
|
+
case 'run.error':
|
|
818
|
+
{
|
|
819
|
+
this._publishEvent('error', { ...content,
|
|
820
|
+
error: isRedelivered ? (0, _Errors.makeErrorFromMessage)(message) : content.error
|
|
821
|
+
}, {
|
|
756
822
|
correlationId
|
|
757
823
|
});
|
|
758
|
-
|
|
759
|
-
|
|
824
|
+
|
|
825
|
+
break;
|
|
760
826
|
}
|
|
761
827
|
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
828
|
+
case 'run.discarded':
|
|
829
|
+
{
|
|
830
|
+
this.logger.debug(`<${content.executionId} (${id})> discarded`);
|
|
831
|
+
this[kCounters].discarded++;
|
|
832
|
+
this.status = 'discarded';
|
|
833
|
+
content.outbound = undefined;
|
|
834
|
+
|
|
835
|
+
if (!isRedelivered) {
|
|
836
|
+
return this._doRunLeave(message, true, () => {
|
|
837
|
+
if (!step) message.ack();
|
|
768
838
|
});
|
|
769
839
|
}
|
|
770
840
|
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
} : undefined)
|
|
774
|
-
}), {
|
|
775
|
-
correlationId
|
|
776
|
-
});
|
|
777
|
-
if (onOutbound) onOutbound();
|
|
778
|
-
});
|
|
779
|
-
}
|
|
780
|
-
}
|
|
841
|
+
break;
|
|
842
|
+
}
|
|
781
843
|
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
if (bpmnIo) bpmnIo.activate((0, _messageHelper.cloneMessage)(message));
|
|
786
|
-
status = 'formatting';
|
|
787
|
-
return formatter(message, (err, formattedContent, formatted) => {
|
|
788
|
-
if (err) return callback(err);
|
|
789
|
-
return callback(null, formatted && formattedContent);
|
|
790
|
-
});
|
|
791
|
-
}
|
|
844
|
+
case 'run.outbound.take':
|
|
845
|
+
{
|
|
846
|
+
const flow = this._getOutboundSequenceFlowById(content.flow.id);
|
|
792
847
|
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
848
|
+
message.ack();
|
|
849
|
+
return flow.take(content.flow);
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
case 'run.outbound.discard':
|
|
853
|
+
{
|
|
854
|
+
const flow = this._getOutboundSequenceFlowById(content.flow.id);
|
|
796
855
|
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
...message.content,
|
|
800
|
-
executionId: executeMessage.content.executionId,
|
|
801
|
-
parent: { ...parent
|
|
856
|
+
message.ack();
|
|
857
|
+
return flow.discard(content.flow);
|
|
802
858
|
}
|
|
803
|
-
});
|
|
804
|
-
const {
|
|
805
|
-
correlationId
|
|
806
|
-
} = message.properties;
|
|
807
|
-
publishEvent(routingKey, content, message.properties);
|
|
808
|
-
|
|
809
|
-
switch (routingKey) {
|
|
810
|
-
case 'execution.outbound.take':
|
|
811
|
-
{
|
|
812
|
-
return doOutbound((0, _messageHelper.cloneMessage)(message), false, (err, outbound) => {
|
|
813
|
-
message.ack();
|
|
814
|
-
if (err) return emitFatal(err, content);
|
|
815
|
-
broker.publish('run', 'run.execute.passthrough', (0, _messageHelper.cloneContent)(content, {
|
|
816
|
-
outbound
|
|
817
|
-
}));
|
|
818
|
-
return ackRunExecuteMessage();
|
|
819
|
-
});
|
|
820
|
-
}
|
|
821
859
|
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
860
|
+
case 'run.leave':
|
|
861
|
+
{
|
|
862
|
+
this.status = undefined;
|
|
863
|
+
if (this.bpmnIo) this.bpmnIo.deactivate(message);
|
|
864
|
+
if (this.extensions) this.extensions.deactivate(message);
|
|
865
|
+
|
|
866
|
+
if (!isRedelivered) {
|
|
867
|
+
this.broker.publish('run', 'run.next', content, {
|
|
868
|
+
persistent: false
|
|
827
869
|
});
|
|
828
|
-
|
|
870
|
+
|
|
871
|
+
this._publishEvent('leave', content, {
|
|
829
872
|
correlationId
|
|
830
873
|
});
|
|
831
|
-
break;
|
|
832
874
|
}
|
|
833
875
|
|
|
834
|
-
case 'execution.discard':
|
|
835
|
-
status = 'discarded';
|
|
836
|
-
broker.publish('run', 'run.discarded', content, {
|
|
837
|
-
correlationId
|
|
838
|
-
});
|
|
839
876
|
break;
|
|
877
|
+
}
|
|
840
878
|
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
status = 'executed';
|
|
844
|
-
broker.publish('run', 'run.end', content, {
|
|
845
|
-
correlationId
|
|
846
|
-
});
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
message.ack();
|
|
851
|
-
ackRunExecuteMessage();
|
|
879
|
+
case 'run.next':
|
|
880
|
+
this._consumeInbound();
|
|
852
881
|
|
|
853
|
-
|
|
854
|
-
if (step) return;
|
|
855
|
-
if (!executeMessage) return;
|
|
856
|
-
const ackMessage = executeMessage;
|
|
857
|
-
executeMessage = null;
|
|
858
|
-
ackMessage.ack();
|
|
859
|
-
}
|
|
882
|
+
break;
|
|
860
883
|
}
|
|
861
884
|
|
|
862
|
-
|
|
863
|
-
|
|
885
|
+
if (!step) message.ack();
|
|
886
|
+
};
|
|
864
887
|
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
888
|
+
proto._onExecutionMessage = function onExecutionMessage(routingKey, message) {
|
|
889
|
+
const executeMessage = this[kExecuteMessage];
|
|
890
|
+
const content = (0, _messageHelper.cloneContent)({ ...executeMessage.content,
|
|
891
|
+
...message.content,
|
|
892
|
+
executionId: executeMessage.content.executionId,
|
|
893
|
+
parent: { ...this.parent
|
|
894
|
+
}
|
|
895
|
+
});
|
|
896
|
+
const {
|
|
897
|
+
correlationId
|
|
898
|
+
} = message.properties;
|
|
871
899
|
|
|
872
|
-
|
|
873
|
-
{
|
|
874
|
-
onStop(message);
|
|
875
|
-
break;
|
|
876
|
-
}
|
|
900
|
+
this._publishEvent(routingKey, content, message.properties);
|
|
877
901
|
|
|
878
|
-
|
|
879
|
-
{
|
|
880
|
-
shakeOutbound(message);
|
|
881
|
-
break;
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
}
|
|
902
|
+
const broker = this.broker;
|
|
885
903
|
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
904
|
+
switch (routingKey) {
|
|
905
|
+
case 'execution.outbound.take':
|
|
906
|
+
{
|
|
907
|
+
return this._doOutbound(message, false, (err, outbound) => {
|
|
908
|
+
message.ack();
|
|
909
|
+
if (err) return this.emitFatal(err, content);
|
|
910
|
+
broker.publish('run', 'run.execute.passthrough', (0, _messageHelper.cloneContent)(content, {
|
|
911
|
+
outbound
|
|
912
|
+
}));
|
|
913
|
+
return this._ackRunExecuteMessage();
|
|
914
|
+
});
|
|
915
|
+
}
|
|
891
916
|
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
917
|
+
case 'execution.error':
|
|
918
|
+
{
|
|
919
|
+
this.status = 'error';
|
|
920
|
+
broker.publish('run', 'run.error', content, {
|
|
921
|
+
correlationId
|
|
922
|
+
});
|
|
923
|
+
broker.publish('run', 'run.discarded', content, {
|
|
924
|
+
correlationId
|
|
925
|
+
});
|
|
926
|
+
break;
|
|
927
|
+
}
|
|
903
928
|
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
929
|
+
case 'execution.discard':
|
|
930
|
+
this.status = 'discarded';
|
|
931
|
+
broker.publish('run', 'run.discarded', content, {
|
|
932
|
+
correlationId
|
|
908
933
|
});
|
|
909
|
-
|
|
934
|
+
break;
|
|
910
935
|
|
|
911
|
-
|
|
936
|
+
default:
|
|
937
|
+
{
|
|
938
|
+
this.status = 'executed';
|
|
939
|
+
broker.publish('run', 'run.end', content, {
|
|
940
|
+
correlationId
|
|
941
|
+
});
|
|
942
|
+
}
|
|
912
943
|
}
|
|
913
944
|
|
|
914
|
-
|
|
915
|
-
if (!state) return;
|
|
916
|
-
if (!content) content = createMessage();
|
|
917
|
-
broker.publish('event', `activity.${state}`, { ...content,
|
|
918
|
-
state
|
|
919
|
-
}, { ...messageProperties,
|
|
920
|
-
type: state,
|
|
921
|
-
mandatory: state === 'error',
|
|
922
|
-
persistent: 'persistent' in messageProperties ? messageProperties.persistent : state !== 'stop'
|
|
923
|
-
});
|
|
924
|
-
}
|
|
945
|
+
message.ack();
|
|
925
946
|
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
const fromContent = fromMessage.content;
|
|
929
|
-
let discardSequence = fromContent.discardSequence;
|
|
947
|
+
this._ackRunExecuteMessage();
|
|
948
|
+
};
|
|
930
949
|
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
950
|
+
proto._ackRunExecuteMessage = function ackRunExecuteMessage() {
|
|
951
|
+
if (this.environment.settings.step) return;
|
|
952
|
+
const executeMessage = this[kExecuteMessage];
|
|
953
|
+
this[kExecuteMessage] = null;
|
|
954
|
+
executeMessage.ack();
|
|
955
|
+
};
|
|
934
956
|
|
|
935
|
-
|
|
957
|
+
proto._doRunLeave = function doRunLeave(message, isDiscarded, onOutbound) {
|
|
958
|
+
const {
|
|
959
|
+
content,
|
|
960
|
+
properties
|
|
961
|
+
} = message;
|
|
962
|
+
const correlationId = properties.correlationId;
|
|
936
963
|
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
}
|
|
964
|
+
if (content.ignoreOutbound) {
|
|
965
|
+
this.broker.publish('run', 'run.leave', (0, _messageHelper.cloneContent)(content), {
|
|
966
|
+
correlationId
|
|
967
|
+
});
|
|
968
|
+
return onOutbound();
|
|
969
|
+
}
|
|
944
970
|
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
return
|
|
971
|
+
return this._doOutbound((0, _messageHelper.cloneMessage)(message), isDiscarded, (err, outbound) => {
|
|
972
|
+
if (err) {
|
|
973
|
+
return this._publishEvent('error', { ...content,
|
|
974
|
+
error: err
|
|
975
|
+
}, {
|
|
976
|
+
correlationId
|
|
977
|
+
});
|
|
948
978
|
}
|
|
949
979
|
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
980
|
+
this.broker.publish('run', 'run.leave', (0, _messageHelper.cloneContent)(content, { ...(outbound.length ? {
|
|
981
|
+
outbound
|
|
982
|
+
} : undefined)
|
|
983
|
+
}), {
|
|
984
|
+
correlationId
|
|
954
985
|
});
|
|
986
|
+
onOutbound();
|
|
987
|
+
});
|
|
988
|
+
};
|
|
955
989
|
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
sequenceId: (0, _shared.getUniqueId)(`${flowId}_${action}`),
|
|
965
|
-
...(discardSequence ? {
|
|
966
|
-
discardSequence: discardSequence.slice()
|
|
967
|
-
} : undefined)
|
|
968
|
-
}
|
|
969
|
-
}));
|
|
970
|
-
return outboundFlow;
|
|
971
|
-
});
|
|
972
|
-
}
|
|
990
|
+
proto._doOutbound = function doOutbound(fromMessage, isDiscarded, callback) {
|
|
991
|
+
const outboundSequenceFlows = this[kFlows].outboundSequenceFlows;
|
|
992
|
+
if (!outboundSequenceFlows.length) return callback(null, []);
|
|
993
|
+
const fromContent = fromMessage.content;
|
|
994
|
+
let discardSequence = fromContent.discardSequence;
|
|
995
|
+
|
|
996
|
+
if (isDiscarded && !discardSequence && this[kFlags].attachedTo && fromContent.inbound && fromContent.inbound[0]) {
|
|
997
|
+
discardSequence = [fromContent.inbound[0].id];
|
|
973
998
|
}
|
|
974
999
|
|
|
975
|
-
|
|
976
|
-
|
|
1000
|
+
let outboundFlows;
|
|
1001
|
+
|
|
1002
|
+
if (isDiscarded) {
|
|
1003
|
+
outboundFlows = outboundSequenceFlows.map(flow => formatFlowAction(flow, {
|
|
977
1004
|
action: 'discard'
|
|
978
|
-
};
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
return { ...options,
|
|
982
|
-
id: flow.id,
|
|
983
|
-
action,
|
|
984
|
-
...(flow.isDefault ? {
|
|
985
|
-
isDefault: true
|
|
986
|
-
} : undefined),
|
|
987
|
-
...(message !== undefined ? {
|
|
988
|
-
message
|
|
989
|
-
} : undefined)
|
|
990
|
-
};
|
|
1005
|
+
}));
|
|
1006
|
+
} else if (fromContent.outbound && fromContent.outbound.length) {
|
|
1007
|
+
outboundFlows = outboundSequenceFlows.map(flow => formatFlowAction(flow, fromContent.outbound.filter(f => f.id === flow.id).pop()));
|
|
991
1008
|
}
|
|
992
1009
|
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
const outbound = {};
|
|
996
|
-
if (!outboundSequenceFlows.length) return completed();
|
|
997
|
-
const content = fromMessage.content;
|
|
998
|
-
const message = content.message;
|
|
999
|
-
const evaluateFlows = outboundSequenceFlows.slice();
|
|
1000
|
-
const defaultFlowIdx = outboundSequenceFlows.findIndex(({
|
|
1001
|
-
isDefault
|
|
1002
|
-
}) => isDefault);
|
|
1003
|
-
|
|
1004
|
-
if (defaultFlowIdx > -1) {
|
|
1005
|
-
evaluateFlows.splice(defaultFlowIdx, 1);
|
|
1006
|
-
evaluateFlows.push(outboundSequenceFlows[defaultFlowIdx]);
|
|
1007
|
-
}
|
|
1010
|
+
if (outboundFlows) {
|
|
1011
|
+
this._doRunOutbound(outboundFlows, fromContent, discardSequence);
|
|
1008
1012
|
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
content: evalContent,
|
|
1012
|
-
ack
|
|
1013
|
-
}) => {
|
|
1014
|
-
const {
|
|
1015
|
-
id: flowId,
|
|
1016
|
-
action
|
|
1017
|
-
} = evalContent;
|
|
1018
|
-
|
|
1019
|
-
if (action === 'take') {
|
|
1020
|
-
takenCount++;
|
|
1021
|
-
conditionMet = true;
|
|
1022
|
-
}
|
|
1013
|
+
return callback(null, outboundFlows);
|
|
1014
|
+
}
|
|
1023
1015
|
|
|
1024
|
-
|
|
1016
|
+
return this.evaluateOutbound(fromMessage, fromContent.outboundTakeOne, (err, evaluatedOutbound) => {
|
|
1017
|
+
if (err) return callback(new _Errors.ActivityError(err.message, fromMessage, err));
|
|
1025
1018
|
|
|
1026
|
-
|
|
1027
|
-
|
|
1019
|
+
const outbound = this._doRunOutbound(evaluatedOutbound, fromContent, discardSequence);
|
|
1020
|
+
|
|
1021
|
+
return callback(null, outbound);
|
|
1022
|
+
});
|
|
1023
|
+
};
|
|
1024
|
+
|
|
1025
|
+
proto._doRunOutbound = function doRunOutbound(outboundList, content, discardSequence) {
|
|
1026
|
+
for (const outboundFlow of outboundList) {
|
|
1027
|
+
const {
|
|
1028
|
+
id: flowId,
|
|
1029
|
+
action
|
|
1030
|
+
} = outboundFlow;
|
|
1031
|
+
this.broker.publish('run', 'run.outbound.' + action, (0, _messageHelper.cloneContent)(content, {
|
|
1032
|
+
flow: { ...outboundFlow,
|
|
1033
|
+
sequenceId: (0, _shared.getUniqueId)(`${flowId}_${action}`),
|
|
1034
|
+
...(discardSequence ? {
|
|
1035
|
+
discardSequence: discardSequence.slice()
|
|
1036
|
+
} : undefined)
|
|
1028
1037
|
}
|
|
1038
|
+
}));
|
|
1039
|
+
}
|
|
1029
1040
|
|
|
1030
|
-
|
|
1031
|
-
|
|
1041
|
+
return outboundList;
|
|
1042
|
+
};
|
|
1032
1043
|
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1044
|
+
proto._onResumeMessage = function onResumeMessage(message) {
|
|
1045
|
+
message.ack();
|
|
1046
|
+
const stateMessage = this[kStateMessage];
|
|
1047
|
+
const {
|
|
1048
|
+
fields
|
|
1049
|
+
} = stateMessage;
|
|
1050
|
+
|
|
1051
|
+
switch (fields.routingKey) {
|
|
1052
|
+
case 'run.enter':
|
|
1053
|
+
case 'run.start':
|
|
1054
|
+
case 'run.discarded':
|
|
1055
|
+
case 'run.end':
|
|
1056
|
+
case 'run.leave':
|
|
1057
|
+
break;
|
|
1058
|
+
|
|
1059
|
+
default:
|
|
1060
|
+
return;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
if (!fields.redelivered) return;
|
|
1064
|
+
this.logger.debug(`<${this.id}> resume from ${message.content.status}`);
|
|
1065
|
+
return this.broker.publish('run', fields.routingKey, (0, _messageHelper.cloneContent)(stateMessage.content), stateMessage.properties);
|
|
1066
|
+
};
|
|
1067
|
+
|
|
1068
|
+
proto._publishEvent = function publishEvent(state, content, properties = {}) {
|
|
1069
|
+
this.broker.publish('event', `activity.${state}`, (0, _messageHelper.cloneContent)(content, {
|
|
1070
|
+
state
|
|
1071
|
+
}), { ...properties,
|
|
1072
|
+
type: state,
|
|
1073
|
+
mandatory: state === 'error',
|
|
1074
|
+
persistent: 'persistent' in properties ? properties.persistent : state !== 'stop'
|
|
1075
|
+
});
|
|
1076
|
+
};
|
|
1077
|
+
|
|
1078
|
+
proto._onStop = function onStop(message) {
|
|
1079
|
+
const running = this[kConsuming];
|
|
1080
|
+
this.stopped = true;
|
|
1081
|
+
this[kConsuming] = false;
|
|
1082
|
+
const broker = this.broker;
|
|
1083
|
+
broker.cancel('_activity-run');
|
|
1084
|
+
broker.cancel('_activity-api');
|
|
1085
|
+
broker.cancel('_activity-execution');
|
|
1086
|
+
broker.cancel('_run-on-inbound');
|
|
1087
|
+
broker.cancel('_format-consumer');
|
|
1088
|
+
|
|
1089
|
+
if (running) {
|
|
1090
|
+
if (this.extensions) this.extensions.deactivate(message || this._createMessage());
|
|
1091
|
+
|
|
1092
|
+
this._publishEvent('stop', this._createMessage());
|
|
1093
|
+
}
|
|
1094
|
+
};
|
|
1095
|
+
|
|
1096
|
+
proto._consumeApi = function consumeApi() {
|
|
1097
|
+
const executionId = this[kExec].executionId;
|
|
1098
|
+
if (!executionId) return;
|
|
1099
|
+
const broker = this.broker;
|
|
1100
|
+
broker.cancel('_activity-api');
|
|
1101
|
+
broker.subscribeTmp('api', `activity.*.${executionId}`, this[kMessageHandlers].onApiMessage, {
|
|
1102
|
+
noAck: true,
|
|
1103
|
+
consumerTag: '_activity-api',
|
|
1104
|
+
priority: 100
|
|
1105
|
+
});
|
|
1106
|
+
};
|
|
1039
1107
|
|
|
1040
|
-
|
|
1108
|
+
proto._onApiMessage = function onApiMessage(routingKey, message) {
|
|
1109
|
+
switch (message.properties.type) {
|
|
1110
|
+
case 'discard':
|
|
1111
|
+
{
|
|
1112
|
+
return this._discardRun(message);
|
|
1041
1113
|
}
|
|
1042
1114
|
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
});
|
|
1047
|
-
return completed();
|
|
1115
|
+
case 'stop':
|
|
1116
|
+
{
|
|
1117
|
+
return this._onStop(message);
|
|
1048
1118
|
}
|
|
1049
1119
|
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1120
|
+
case 'shake':
|
|
1121
|
+
{
|
|
1122
|
+
return this._shakeOutbound(message);
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
|
|
1127
|
+
proto._createMessage = function createMessage(override) {
|
|
1128
|
+
const name = this.name,
|
|
1129
|
+
status = this.status,
|
|
1130
|
+
parent = this.parent;
|
|
1131
|
+
const result = { ...override,
|
|
1132
|
+
id: this.id,
|
|
1133
|
+
type: this.type,
|
|
1134
|
+
...(name ? {
|
|
1135
|
+
name
|
|
1136
|
+
} : undefined),
|
|
1137
|
+
...(status ? {
|
|
1138
|
+
status
|
|
1139
|
+
} : undefined),
|
|
1140
|
+
...(parent ? {
|
|
1141
|
+
parent: (0, _messageHelper.cloneParent)(parent)
|
|
1142
|
+
} : undefined)
|
|
1143
|
+
};
|
|
1056
1144
|
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1145
|
+
for (const [flag, value] of Object.entries(this[kFlags])) {
|
|
1146
|
+
if (value) result[flag] = value;
|
|
1147
|
+
}
|
|
1060
1148
|
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1149
|
+
return result;
|
|
1150
|
+
};
|
|
1151
|
+
|
|
1152
|
+
proto._getOutboundSequenceFlowById = function getOutboundSequenceFlowById(flowId) {
|
|
1153
|
+
return this[kFlows].outboundSequenceFlows.find(flow => flow.id === flowId);
|
|
1154
|
+
};
|
|
1155
|
+
|
|
1156
|
+
proto._resumeExtensions = function resumeExtensions(message, callback) {
|
|
1157
|
+
const extensions = this.extensions,
|
|
1158
|
+
bpmnIo = this.bpmnIo;
|
|
1159
|
+
if (!extensions && !bpmnIo) return callback();
|
|
1160
|
+
if (extensions) extensions.activate((0, _messageHelper.cloneMessage)(message), this);
|
|
1161
|
+
if (bpmnIo) bpmnIo.activate((0, _messageHelper.cloneMessage)(message), this);
|
|
1162
|
+
this.status = 'formatting';
|
|
1163
|
+
return this.formatter.format(message, (err, formattedContent, formatted) => {
|
|
1164
|
+
if (err) return callback(err);
|
|
1165
|
+
return callback(null, formatted && formattedContent);
|
|
1166
|
+
});
|
|
1167
|
+
};
|
|
1168
|
+
|
|
1169
|
+
proto._deactivateRunConsumers = function _deactivateRunConsumers() {
|
|
1170
|
+
const broker = this.broker;
|
|
1171
|
+
broker.cancel('_activity-api');
|
|
1172
|
+
broker.cancel('_activity-run');
|
|
1173
|
+
broker.cancel('_activity-execution');
|
|
1174
|
+
this[kConsuming] = false;
|
|
1175
|
+
};
|
|
1176
|
+
|
|
1177
|
+
function OutboundEvaluator(activity, outboundFlows) {
|
|
1178
|
+
this.activity = activity;
|
|
1179
|
+
this.broker = activity.broker;
|
|
1180
|
+
const flows = this.outboundFlows = outboundFlows.slice();
|
|
1181
|
+
const defaultFlowIdx = flows.findIndex(({
|
|
1182
|
+
isDefault
|
|
1183
|
+
}) => isDefault);
|
|
1184
|
+
|
|
1185
|
+
if (defaultFlowIdx > -1) {
|
|
1186
|
+
const [defaultFlow] = flows.splice(defaultFlowIdx, 1);
|
|
1187
|
+
flows.push(defaultFlow);
|
|
1188
|
+
}
|
|
1066
1189
|
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1190
|
+
this.defaultFlowIdx = outboundFlows.findIndex(({
|
|
1191
|
+
isDefault
|
|
1192
|
+
}) => isDefault);
|
|
1193
|
+
this._onEvaluated = this.onEvaluated.bind(this);
|
|
1194
|
+
this.evaluateArgs = {};
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
OutboundEvaluator.prototype.evaluate = function evaluate(fromMessage, discardRestAtTake, callback) {
|
|
1198
|
+
const outboundFlows = this.outboundFlows;
|
|
1199
|
+
const args = this.evaluateArgs = {
|
|
1200
|
+
fromMessage,
|
|
1201
|
+
evaluationId: fromMessage.content.executionId,
|
|
1202
|
+
discardRestAtTake,
|
|
1203
|
+
callback,
|
|
1204
|
+
conditionMet: false,
|
|
1205
|
+
result: {},
|
|
1206
|
+
takenCount: 0
|
|
1207
|
+
};
|
|
1208
|
+
if (!outboundFlows.length) return this.completed();
|
|
1209
|
+
const flows = args.flows = outboundFlows.slice();
|
|
1210
|
+
this.broker.subscribeTmp('execution', 'evaluate.flow.#', this._onEvaluated, {
|
|
1211
|
+
consumerTag: `_flow-evaluation-${args.evaluationId}`
|
|
1212
|
+
});
|
|
1213
|
+
return this.evaluateFlow(flows.shift());
|
|
1214
|
+
};
|
|
1078
1215
|
|
|
1079
|
-
|
|
1080
|
-
|
|
1216
|
+
OutboundEvaluator.prototype.onEvaluated = function onEvaluated(routingKey, message) {
|
|
1217
|
+
const content = message.content;
|
|
1218
|
+
const {
|
|
1219
|
+
id: flowId,
|
|
1220
|
+
action,
|
|
1221
|
+
evaluationId
|
|
1222
|
+
} = message.content;
|
|
1223
|
+
const args = this.evaluateArgs;
|
|
1224
|
+
|
|
1225
|
+
if (action === 'take') {
|
|
1226
|
+
args.takenCount++;
|
|
1227
|
+
args.conditionMet = true;
|
|
1228
|
+
}
|
|
1081
1229
|
|
|
1082
|
-
|
|
1083
|
-
return broker.publish('execution', 'evaluate.flow.take', formatFlowAction(flow, {
|
|
1084
|
-
action: 'take'
|
|
1085
|
-
}), {
|
|
1086
|
-
persistent: false
|
|
1087
|
-
});
|
|
1088
|
-
}
|
|
1230
|
+
args.result[flowId] = content;
|
|
1089
1231
|
|
|
1090
|
-
|
|
1232
|
+
if ('result' in content) {
|
|
1233
|
+
this.activity.logger.debug(`<${evaluationId} (${this.activity.id})> flow <${flowId}> evaluated to: ${!!content.result}`);
|
|
1234
|
+
}
|
|
1091
1235
|
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
action: 'take'
|
|
1095
|
-
}), {
|
|
1096
|
-
persistent: false
|
|
1097
|
-
});
|
|
1098
|
-
}
|
|
1236
|
+
let nextFlow = args.flows.shift();
|
|
1237
|
+
if (!nextFlow) return this.completed();
|
|
1099
1238
|
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
action,
|
|
1105
|
-
result
|
|
1106
|
-
}), {
|
|
1107
|
-
persistent: false
|
|
1108
|
-
});
|
|
1239
|
+
if (args.discardRestAtTake && args.conditionMet) {
|
|
1240
|
+
do {
|
|
1241
|
+
args.result[nextFlow.id] = formatFlowAction(nextFlow, {
|
|
1242
|
+
action: 'discard'
|
|
1109
1243
|
});
|
|
1110
|
-
}
|
|
1244
|
+
} while (nextFlow = args.flows.shift());
|
|
1245
|
+
|
|
1246
|
+
return this.completed();
|
|
1111
1247
|
}
|
|
1112
1248
|
|
|
1113
|
-
|
|
1114
|
-
|
|
1249
|
+
if (args.conditionMet && nextFlow.isDefault) {
|
|
1250
|
+
args.result[nextFlow.id] = formatFlowAction(nextFlow, {
|
|
1251
|
+
action: 'discard'
|
|
1252
|
+
});
|
|
1253
|
+
return this.completed();
|
|
1115
1254
|
}
|
|
1116
1255
|
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
};
|
|
1256
|
+
message.ack();
|
|
1257
|
+
this.evaluateFlow(nextFlow);
|
|
1258
|
+
};
|
|
1259
|
+
|
|
1260
|
+
OutboundEvaluator.prototype.evaluateFlow = function evaluateFlow(flow) {
|
|
1261
|
+
const broker = this.broker;
|
|
1262
|
+
|
|
1263
|
+
if (flow.isDefault) {
|
|
1264
|
+
return broker.publish('execution', 'evaluate.flow.take', formatFlowAction(flow, {
|
|
1265
|
+
action: 'take'
|
|
1266
|
+
}), {
|
|
1267
|
+
persistent: false
|
|
1268
|
+
});
|
|
1130
1269
|
}
|
|
1131
1270
|
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1271
|
+
const flowCondition = flow.getCondition();
|
|
1272
|
+
|
|
1273
|
+
if (!flowCondition) {
|
|
1274
|
+
return broker.publish('execution', 'evaluate.flow.take', formatFlowAction(flow, {
|
|
1275
|
+
action: 'take'
|
|
1276
|
+
}), {
|
|
1277
|
+
persistent: false
|
|
1278
|
+
});
|
|
1140
1279
|
}
|
|
1141
1280
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1281
|
+
const {
|
|
1282
|
+
fromMessage,
|
|
1283
|
+
evaluationId
|
|
1284
|
+
} = this.evaluateArgs;
|
|
1285
|
+
flowCondition.execute((0, _messageHelper.cloneMessage)(fromMessage), (err, result) => {
|
|
1286
|
+
if (err) return this.completed(err);
|
|
1287
|
+
const action = result ? 'take' : 'discard';
|
|
1288
|
+
return broker.publish('execution', 'evaluate.flow.' + action, formatFlowAction(flow, {
|
|
1289
|
+
action,
|
|
1290
|
+
result,
|
|
1291
|
+
evaluationId
|
|
1292
|
+
}), {
|
|
1293
|
+
persistent: false
|
|
1294
|
+
});
|
|
1295
|
+
});
|
|
1296
|
+
};
|
|
1297
|
+
|
|
1298
|
+
OutboundEvaluator.prototype.completed = function completed(err) {
|
|
1299
|
+
const {
|
|
1300
|
+
callback,
|
|
1301
|
+
evaluationId,
|
|
1302
|
+
fromMessage,
|
|
1303
|
+
result,
|
|
1304
|
+
takenCount
|
|
1305
|
+
} = this.evaluateArgs;
|
|
1306
|
+
this.broker.cancel(`_flow-evaluation-${evaluationId}`);
|
|
1307
|
+
if (err) return callback(err);
|
|
1308
|
+
|
|
1309
|
+
if (!takenCount && this.outboundFlows.length) {
|
|
1310
|
+
const nonTakenError = new _Errors.ActivityError(`<${this.activity.id}> no conditional flow taken`, fromMessage);
|
|
1311
|
+
return callback(nonTakenError);
|
|
1145
1312
|
}
|
|
1313
|
+
|
|
1314
|
+
const message = fromMessage.content.message;
|
|
1315
|
+
const evaluationResult = [];
|
|
1316
|
+
|
|
1317
|
+
for (const flow of Object.values(result)) {
|
|
1318
|
+
evaluationResult.push({ ...flow,
|
|
1319
|
+
...(message !== undefined ? {
|
|
1320
|
+
message
|
|
1321
|
+
} : undefined)
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
return callback(null, evaluationResult);
|
|
1326
|
+
};
|
|
1327
|
+
|
|
1328
|
+
function formatFlowAction(flow, options) {
|
|
1329
|
+
return { ...options,
|
|
1330
|
+
id: flow.id,
|
|
1331
|
+
action: options.action,
|
|
1332
|
+
...(flow.isDefault ? {
|
|
1333
|
+
isDefault: true
|
|
1334
|
+
} : undefined)
|
|
1335
|
+
};
|
|
1146
1336
|
}
|