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/tasks/SignalTask.js
CHANGED
|
@@ -1,71 +1,96 @@
|
|
|
1
1
|
import Activity from '../activity/Activity';
|
|
2
|
-
import {
|
|
2
|
+
import {ActivityError} from '../error/Errors';
|
|
3
3
|
import {cloneContent} from '../messageHelper';
|
|
4
4
|
|
|
5
5
|
export default function SignalTask(activityDef, context) {
|
|
6
|
-
return Activity(SignalTaskBehaviour, activityDef, context);
|
|
6
|
+
return new Activity(SignalTaskBehaviour, activityDef, context);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export function SignalTaskBehaviour(activity) {
|
|
10
|
-
const {id, type, behaviour
|
|
11
|
-
const loopCharacteristics = behaviour.loopCharacteristics && behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
|
|
10
|
+
const {id, type, behaviour} = activity;
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
this.id = id;
|
|
13
|
+
this.type = type;
|
|
14
|
+
this.loopCharacteristics = behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
|
|
15
|
+
this.activity = activity;
|
|
16
|
+
this.broker = activity.broker;
|
|
17
|
+
}
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
const proto = SignalTaskBehaviour.prototype;
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
proto.execute = function execute(executeMessage) {
|
|
22
|
+
const executeContent = executeMessage.content;
|
|
23
|
+
const loopCharacteristics = this.loopCharacteristics;
|
|
24
|
+
if (loopCharacteristics && executeContent.isRootScope) {
|
|
25
|
+
return loopCharacteristics.execute(executeMessage);
|
|
26
|
+
}
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
const executionId = executeContent.executionId;
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const broker = this.broker;
|
|
31
|
+
broker.subscribeTmp('api', `activity.#.${executionId}`, (...args) => this._onApiMessage(executeMessage, ...args), {
|
|
32
|
+
noAck: true,
|
|
33
|
+
consumerTag: `_api-${executionId}`,
|
|
34
|
+
});
|
|
35
|
+
broker.subscribeTmp('api', '#.signal.*', (...args) => this._onDelegatedApiMessage(executeMessage, ...args), {
|
|
36
|
+
noAck: true,
|
|
37
|
+
consumerTag: `_api-delegated-${executionId}`,
|
|
38
|
+
});
|
|
39
|
+
broker.publish('event', 'activity.wait', cloneContent(executeContent, {state: 'wait'}));
|
|
40
|
+
};
|
|
33
41
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const {content: delegateContent} = message;
|
|
37
|
-
if (!delegateContent || !delegateContent.message) return;
|
|
42
|
+
proto._onDelegatedApiMessage = function onDelegatedApiMessage(executeMessage, routingKey, message) {
|
|
43
|
+
if (!message.properties.delegate) return;
|
|
38
44
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (signalId !== id && signalExecutionId !== executionId) return;
|
|
45
|
+
const {content: delegateContent} = message;
|
|
46
|
+
if (!delegateContent || !delegateContent.message) return;
|
|
42
47
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
const executeContent = executeMessage.content;
|
|
49
|
+
const {id: signalId, executionId: signalExecutionId} = delegateContent.message;
|
|
50
|
+
if (this.loopCharacteristics && signalExecutionId !== executeContent.executionId) return;
|
|
51
|
+
if (signalId !== this.id && signalExecutionId !== executeContent.executionId) return;
|
|
47
52
|
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
const {type: messageType, correlationId} = message.properties;
|
|
54
|
+
this.broker.publish('event', 'activity.consumed', cloneContent(executeContent, {
|
|
55
|
+
message: { ...delegateContent.message},
|
|
56
|
+
}), {
|
|
57
|
+
correlationId,
|
|
58
|
+
type: messageType,
|
|
59
|
+
});
|
|
50
60
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return stop();
|
|
54
|
-
case 'signal':
|
|
55
|
-
stop();
|
|
56
|
-
return broker.publish('execution', 'execute.completed', cloneContent(content, {output: message.content.message, state: 'signal'}), {correlationId});
|
|
57
|
-
case 'error':
|
|
58
|
-
stop();
|
|
59
|
-
return broker.publish('execution', 'execute.error', cloneContent(content, {error: new ActivityError(message.content.message, executeMessage, message.content)}, {mandatory: true, correlationId}));
|
|
60
|
-
case 'discard':
|
|
61
|
-
stop();
|
|
62
|
-
return broker.publish('execution', 'execute.discard', cloneContent(content), {correlationId});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
61
|
+
return this._onApiMessage(executeMessage, routingKey, message);
|
|
62
|
+
};
|
|
65
63
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
proto._onApiMessage = function onApiMessage(executeMessage, routingKey, message) {
|
|
65
|
+
const {type: messageType, correlationId} = message.properties;
|
|
66
|
+
const executeContent = executeMessage.content;
|
|
67
|
+
switch (messageType) {
|
|
68
|
+
case 'stop':
|
|
69
|
+
return this._stop(executeContent.executionId);
|
|
70
|
+
case 'signal':
|
|
71
|
+
this._stop(executeContent.executionId);
|
|
72
|
+
return this.broker.publish('execution', 'execute.completed', cloneContent(executeContent, {
|
|
73
|
+
output: message.content.message,
|
|
74
|
+
state: 'signal',
|
|
75
|
+
}), {
|
|
76
|
+
correlationId,
|
|
77
|
+
});
|
|
78
|
+
case 'error':
|
|
79
|
+
this._stop(executeContent.executionId);
|
|
80
|
+
return this.broker.publish('execution', 'execute.error', cloneContent(executeContent, {
|
|
81
|
+
error: new ActivityError(message.content.message, executeMessage, message.content),
|
|
82
|
+
}, {
|
|
83
|
+
mandatory: true,
|
|
84
|
+
correlationId,
|
|
85
|
+
}));
|
|
86
|
+
case 'discard':
|
|
87
|
+
this._stop(executeContent.executionId);
|
|
88
|
+
return this.broker.publish('execution', 'execute.discard', cloneContent(executeContent), {correlationId});
|
|
70
89
|
}
|
|
71
|
-
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
proto._stop = function stop(executionId) {
|
|
93
|
+
const broker = this.broker;
|
|
94
|
+
broker.cancel(`_api-${executionId}`);
|
|
95
|
+
broker.cancel(`_api-delegated-${executionId}`);
|
|
96
|
+
};
|
|
@@ -3,6 +3,6 @@ import LoopCharacteristics from './LoopCharacteristics';
|
|
|
3
3
|
export default function StandardLoopCharacteristics(activity, loopCharacteristics) {
|
|
4
4
|
let {behaviour} = loopCharacteristics;
|
|
5
5
|
behaviour = {...behaviour, isSequential: true};
|
|
6
|
-
return LoopCharacteristics(activity, {...loopCharacteristics, behaviour});
|
|
6
|
+
return new LoopCharacteristics(activity, {...loopCharacteristics, behaviour});
|
|
7
7
|
}
|
|
8
8
|
|
package/src/tasks/SubProcess.js
CHANGED
|
@@ -2,9 +2,12 @@ import Activity from '../activity/Activity';
|
|
|
2
2
|
import ProcessExecution from '../process/ProcessExecution';
|
|
3
3
|
import {cloneContent} from '../messageHelper';
|
|
4
4
|
|
|
5
|
+
const executionsSymbol = Symbol.for('executions');
|
|
6
|
+
const messageHandlersSymbol = Symbol.for('messageHandlers');
|
|
7
|
+
|
|
5
8
|
export default function SubProcess(activityDef, context) {
|
|
6
9
|
const triggeredByEvent = activityDef.behaviour && activityDef.behaviour.triggeredByEvent;
|
|
7
|
-
const subProcess = Activity(SubProcessBehaviour, {...activityDef, isSubProcess: true, triggeredByEvent}, context);
|
|
10
|
+
const subProcess = new Activity(SubProcessBehaviour, {...activityDef, isSubProcess: true, triggeredByEvent}, context);
|
|
8
11
|
|
|
9
12
|
subProcess.getStartActivities = function getStartActivities(filterOptions) {
|
|
10
13
|
return context.getStartActivities(filterOptions, activityDef.id);
|
|
@@ -18,205 +21,229 @@ export default function SubProcess(activityDef, context) {
|
|
|
18
21
|
function onShake(_, message) {
|
|
19
22
|
const {startId} = message.content;
|
|
20
23
|
const last = message.content.sequence.pop();
|
|
21
|
-
const sequence = ProcessExecution(subProcess, context).shake(startId);
|
|
24
|
+
const sequence = new ProcessExecution(subProcess, context).shake(startId);
|
|
22
25
|
message.content.sequence.push({...last, isSubProcess: true, sequence});
|
|
23
26
|
}
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
export function SubProcessBehaviour(activity, context) {
|
|
27
|
-
const {id, type,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return processExecutions;
|
|
42
|
-
},
|
|
43
|
-
execute,
|
|
44
|
-
getApi,
|
|
45
|
-
getState,
|
|
46
|
-
getPostponed() {
|
|
47
|
-
return this.executions.reduce((result, pe) => {
|
|
48
|
-
result = result.concat(pe.getPostponed());
|
|
49
|
-
return result;
|
|
50
|
-
}, []);
|
|
51
|
-
},
|
|
52
|
-
recover,
|
|
30
|
+
const {id, type, behaviour} = activity;
|
|
31
|
+
this.id = id;
|
|
32
|
+
this.type = type;
|
|
33
|
+
this.loopCharacteristics = behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
|
|
34
|
+
this.activity = activity;
|
|
35
|
+
this.context = context;
|
|
36
|
+
this.environment = activity.environment;
|
|
37
|
+
this.broker = activity.broker;
|
|
38
|
+
this.executionId = undefined;
|
|
39
|
+
|
|
40
|
+
this[executionsSymbol] = [];
|
|
41
|
+
this[messageHandlersSymbol] = {
|
|
42
|
+
onApiRootMessage: this._onApiRootMessage.bind(this),
|
|
43
|
+
onExecutionCompleted: this._onExecutionCompleted.bind(this),
|
|
53
44
|
};
|
|
45
|
+
}
|
|
54
46
|
|
|
55
|
-
|
|
47
|
+
const proto = SubProcessBehaviour.prototype;
|
|
56
48
|
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
Object.defineProperty(proto, 'execution', {
|
|
50
|
+
get() {
|
|
51
|
+
return this[executionsSymbol][0];
|
|
52
|
+
},
|
|
53
|
+
});
|
|
59
54
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
Object.defineProperty(proto, 'executions', {
|
|
56
|
+
get() {
|
|
57
|
+
return this[executionsSymbol].slice();
|
|
58
|
+
},
|
|
59
|
+
});
|
|
63
60
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return loopCharacteristics.execute(executeMessage);
|
|
67
|
-
}
|
|
61
|
+
proto.execute = function execute(executeMessage) {
|
|
62
|
+
const content = executeMessage.content;
|
|
68
63
|
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
let executionId = this.executionId;
|
|
65
|
+
if (content.isRootScope) {
|
|
66
|
+
executionId = this.executionId = content.executionId;
|
|
67
|
+
}
|
|
71
68
|
|
|
72
|
-
|
|
69
|
+
const loopCharacteristics = this.loopCharacteristics;
|
|
70
|
+
if (loopCharacteristics && content.isRootScope) {
|
|
71
|
+
this.broker.subscribeTmp('api', `activity.#.${executionId}`, this[messageHandlersSymbol].onApiRootMessage, {
|
|
72
|
+
noAck: true,
|
|
73
|
+
consumerTag: `_api-${executionId}`,
|
|
74
|
+
priority: 200,
|
|
75
|
+
});
|
|
73
76
|
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
return loopCharacteristics.execute(executeMessage);
|
|
78
|
+
}
|
|
76
79
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
const processExecution = this._upsertExecution(executeMessage);
|
|
81
|
+
if (!processExecution) return;
|
|
82
|
+
|
|
83
|
+
return processExecution.execute(executeMessage);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
proto.stop = function stop() {
|
|
87
|
+
for (const execution of this[executionsSymbol]) {
|
|
88
|
+
this.broker.cancel(`_sub-process-execution-${execution.executionId}`);
|
|
89
|
+
this.broker.cancel(`_sub-process-api-${execution.executionId}`);
|
|
90
|
+
execution.stop();
|
|
88
91
|
}
|
|
92
|
+
};
|
|
89
93
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
proto.discard = function discard() {
|
|
95
|
+
for (const execution of this[executionsSymbol]) {
|
|
96
|
+
this.broker.cancel(`_sub-process-execution-${execution.executionId}`);
|
|
97
|
+
this.broker.cancel(`_sub-process-api-${execution.executionId}`);
|
|
98
|
+
execution.discard();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
proto.getState = function getState() {
|
|
103
|
+
if (this.loopCharacteristics) {
|
|
104
|
+
return {
|
|
105
|
+
executions: this[executionsSymbol].map((pe) => {
|
|
106
|
+
const state = pe.getState();
|
|
107
|
+
state.environment = pe.environment.getState();
|
|
108
|
+
return state;
|
|
109
|
+
}),
|
|
110
|
+
};
|
|
96
111
|
}
|
|
97
112
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
});
|
|
113
|
+
const execution = this.execution;
|
|
114
|
+
if (execution) {
|
|
115
|
+
const state = execution.getState();
|
|
116
|
+
state.environment = execution.environment.getState();
|
|
117
|
+
return state;
|
|
104
118
|
}
|
|
119
|
+
};
|
|
105
120
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return {
|
|
109
|
-
executions: processExecutions.map(getExecutionState),
|
|
110
|
-
};
|
|
111
|
-
}
|
|
121
|
+
proto.recover = function recover(state) {
|
|
122
|
+
if (!state) return;
|
|
112
123
|
|
|
113
|
-
|
|
114
|
-
return getExecutionState(processExecutions[0]);
|
|
115
|
-
}
|
|
124
|
+
const executions = this[executionsSymbol];
|
|
116
125
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
126
|
+
const loopCharacteristics = this.loopCharacteristics;
|
|
127
|
+
if (loopCharacteristics && state.executions) {
|
|
128
|
+
executions.splice(0);
|
|
129
|
+
for (const se of state.executions) {
|
|
130
|
+
this.recover(se);
|
|
121
131
|
}
|
|
132
|
+
return;
|
|
122
133
|
}
|
|
123
134
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (loopCharacteristics && state.executions) {
|
|
128
|
-
processExecutions.splice(0);
|
|
129
|
-
return state.executions.forEach(recover);
|
|
130
|
-
} else if (!loopCharacteristics) {
|
|
131
|
-
processExecutions.splice(0);
|
|
132
|
-
}
|
|
135
|
+
if (!loopCharacteristics) {
|
|
136
|
+
executions.splice(0);
|
|
137
|
+
}
|
|
133
138
|
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
const subEnvironment = this.environment.clone().recover(state.environment);
|
|
140
|
+
const subContext = this.context.clone(subEnvironment);
|
|
141
|
+
|
|
142
|
+
const execution = new ProcessExecution(this.activity, subContext).recover(state);
|
|
143
|
+
|
|
144
|
+
executions.push(execution);
|
|
145
|
+
return execution;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
proto.getPostponed = function getPostponed() {
|
|
149
|
+
return this[executionsSymbol].reduce((result, pe) => {
|
|
150
|
+
result = result.concat(pe.getPostponed());
|
|
151
|
+
return result;
|
|
152
|
+
}, []);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
proto._onApiRootMessage = function onApiRootMessage(_, message) {
|
|
156
|
+
const messageType = message.properties.type;
|
|
157
|
+
|
|
158
|
+
switch (messageType) {
|
|
159
|
+
case 'stop':
|
|
160
|
+
this.broker.cancel(message.fields.consumerTag);
|
|
161
|
+
this.stop();
|
|
162
|
+
break;
|
|
163
|
+
case 'discard':
|
|
164
|
+
this.broker.cancel(message.fields.consumerTag);
|
|
165
|
+
this.discard();
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
136
169
|
|
|
137
|
-
|
|
170
|
+
proto._upsertExecution = function upsertExecution(executeMessage) {
|
|
171
|
+
const content = executeMessage.content;
|
|
172
|
+
const executionId = content.executionId;
|
|
138
173
|
|
|
139
|
-
|
|
174
|
+
let execution = this._getExecutionById(executionId);
|
|
175
|
+
if (execution) {
|
|
176
|
+
if (executeMessage.fields.redelivered) this._addListeners(execution, executionId);
|
|
140
177
|
return execution;
|
|
141
178
|
}
|
|
142
179
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const executionId = content.executionId;
|
|
180
|
+
const subEnvironment = this.environment.clone({ output: {} });
|
|
181
|
+
const subContext = this.context.clone(subEnvironment);
|
|
146
182
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (executeMessage.fields.redelivered) addListeners(execution, executionId);
|
|
150
|
-
return execution;
|
|
151
|
-
}
|
|
183
|
+
execution = new ProcessExecution(this.activity, subContext);
|
|
184
|
+
this[executionsSymbol].push(execution);
|
|
152
185
|
|
|
153
|
-
|
|
154
|
-
const subContext = context.clone(subEnvironment);
|
|
186
|
+
this._addListeners(execution, executionId);
|
|
155
187
|
|
|
156
|
-
|
|
157
|
-
|
|
188
|
+
return execution;
|
|
189
|
+
};
|
|
158
190
|
|
|
159
|
-
|
|
191
|
+
proto._addListeners = function addListeners(processExecution, executionId) {
|
|
192
|
+
this.broker.subscribeTmp('subprocess-execution', `execution.#.${executionId}`, this[messageHandlersSymbol].onExecutionCompleted, {
|
|
193
|
+
noAck: true,
|
|
194
|
+
consumerTag: `_sub-process-execution-${executionId}`,
|
|
195
|
+
});
|
|
196
|
+
};
|
|
160
197
|
|
|
161
|
-
|
|
162
|
-
|
|
198
|
+
proto._onExecutionCompleted = function onExecutionCompleted(_, message) {
|
|
199
|
+
if (message.fields.redelivered && message.properties.persistent === false) return;
|
|
163
200
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if (message.fields.redelivered && message.properties.persistent === false) return;
|
|
174
|
-
|
|
175
|
-
switch (messageType) {
|
|
176
|
-
case 'stopped': {
|
|
177
|
-
broker.cancel(executionConsumerTag);
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
case 'discard': {
|
|
181
|
-
broker.cancel(executionConsumerTag);
|
|
182
|
-
broker.publish('execution', 'execute.discard', cloneContent(content));
|
|
183
|
-
break;
|
|
184
|
-
}
|
|
185
|
-
case 'completed': {
|
|
186
|
-
broker.cancel(executionConsumerTag);
|
|
187
|
-
broker.publish('execution', 'execute.completed', cloneContent(content));
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
190
|
-
case 'error': {
|
|
191
|
-
broker.cancel(executionConsumerTag);
|
|
192
|
-
|
|
193
|
-
const {error} = content;
|
|
194
|
-
logger.error(`<${id}>`, error);
|
|
195
|
-
broker.publish('execution', 'execute.error', cloneContent(content));
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
201
|
+
const content = message.content;
|
|
202
|
+
const messageType = message.properties.type;
|
|
203
|
+
const broker = this.broker;
|
|
204
|
+
|
|
205
|
+
switch (messageType) {
|
|
206
|
+
case 'stopped': {
|
|
207
|
+
broker.cancel(message.fields.consumerTag);
|
|
208
|
+
break;
|
|
199
209
|
}
|
|
200
|
-
|
|
210
|
+
case 'discard': {
|
|
211
|
+
broker.cancel(message.fields.consumerTag);
|
|
212
|
+
broker.publish('execution', 'execute.discard', cloneContent(content));
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
case 'completed': {
|
|
216
|
+
broker.cancel(message.fields.consumerTag);
|
|
217
|
+
broker.publish('execution', 'execute.completed', cloneContent(content));
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
case 'error': {
|
|
221
|
+
broker.cancel(message.fields.consumerTag);
|
|
201
222
|
|
|
202
|
-
|
|
203
|
-
|
|
223
|
+
const {error} = content;
|
|
224
|
+
this.activity.logger.error(`<${this.id}>`, error);
|
|
225
|
+
broker.publish('execution', 'execute.error', cloneContent(content));
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
};
|
|
204
230
|
|
|
205
|
-
|
|
231
|
+
proto.getApi = function getApi(apiMessage) {
|
|
232
|
+
const content = apiMessage.content;
|
|
206
233
|
|
|
207
|
-
|
|
208
|
-
if ((execution = getExecutionById(content.parent.executionId))) {
|
|
209
|
-
return execution.getApi(apiMessage);
|
|
210
|
-
}
|
|
234
|
+
if (content.id === this.id) return;
|
|
211
235
|
|
|
212
|
-
|
|
236
|
+
let execution;
|
|
213
237
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
238
|
+
if ((execution = this._getExecutionById(content.parent.executionId))) {
|
|
239
|
+
return execution.getApi(apiMessage);
|
|
217
240
|
}
|
|
218
241
|
|
|
219
|
-
|
|
220
|
-
|
|
242
|
+
for (const pp of content.parent.path) {
|
|
243
|
+
if ((execution = this._getExecutionById(pp.executionId))) return execution.getApi(apiMessage);
|
|
221
244
|
}
|
|
222
|
-
}
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
proto._getExecutionById = function getExecutionById(executionId) {
|
|
248
|
+
return this[executionsSymbol].find((pe) => pe.executionId === executionId);
|
|
249
|
+
};
|
package/src/tasks/Task.js
CHANGED
|
@@ -1,28 +1,24 @@
|
|
|
1
1
|
import Activity from '../activity/Activity';
|
|
2
|
+
import {cloneContent} from '../messageHelper';
|
|
2
3
|
|
|
3
4
|
export default function Task(activityDef, context) {
|
|
4
|
-
return Activity(TaskBehaviour, activityDef, context);
|
|
5
|
+
return new Activity(TaskBehaviour, activityDef, context);
|
|
5
6
|
}
|
|
6
7
|
|
|
7
8
|
export function TaskBehaviour(activity) {
|
|
8
9
|
const {id, type, behaviour, broker} = activity;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
loopCharacteristics,
|
|
15
|
-
execute,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
return source;
|
|
19
|
-
|
|
20
|
-
function execute(executeMessage) {
|
|
21
|
-
const content = executeMessage.content;
|
|
22
|
-
if (loopCharacteristics && content.isRootScope) {
|
|
23
|
-
return loopCharacteristics.execute(executeMessage);
|
|
24
|
-
}
|
|
10
|
+
this.id = id;
|
|
11
|
+
this.type = type;
|
|
12
|
+
this.loopCharacteristics = behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
|
|
13
|
+
this.broker = broker;
|
|
14
|
+
}
|
|
25
15
|
|
|
26
|
-
|
|
16
|
+
TaskBehaviour.prototype.execute = function execute(executeMessage) {
|
|
17
|
+
const executeContent = executeMessage.content;
|
|
18
|
+
const loopCharacteristics = this.loopCharacteristics;
|
|
19
|
+
if (loopCharacteristics && executeContent.isRootScope) {
|
|
20
|
+
return loopCharacteristics.execute(executeMessage);
|
|
27
21
|
}
|
|
28
|
-
|
|
22
|
+
|
|
23
|
+
return this.broker.publish('execution', 'execute.completed', cloneContent(executeContent));
|
|
24
|
+
};
|