bpmn-elements 13.1.2 → 14.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/README.md +1 -2
- package/dist/Context.js +36 -2
- package/dist/activity/Activity.js +32 -15
- package/dist/definition/DefinitionExecution.js +1 -1
- package/dist/error/Errors.js +6 -1
- package/dist/eventDefinitions/TimerEventDefinition.js +18 -31
- package/dist/getPropertyValue.js +1 -2
- package/dist/index.js +13 -5
- package/package.json +16 -14
- package/src/Api.js +18 -20
- package/src/Context.js +49 -7
- package/src/Environment.js +10 -20
- package/src/EventBroker.js +21 -27
- package/src/MessageFormatter.js +23 -19
- package/src/Tracker.js +4 -4
- package/src/activity/Activity.js +174 -121
- package/src/activity/ActivityExecution.js +38 -29
- package/src/activity/Dummy.js +3 -3
- package/src/activity/Escalation.js +4 -4
- package/src/activity/ExecutionScope.js +4 -4
- package/src/activity/Message.js +5 -5
- package/src/activity/Signal.js +5 -5
- package/src/definition/Definition.js +44 -36
- package/src/definition/DefinitionExecution.js +97 -66
- package/src/error/BpmnError.js +3 -3
- package/src/error/Errors.js +27 -15
- package/src/eventDefinitions/CancelEventDefinition.js +16 -11
- package/src/eventDefinitions/CompensateEventDefinition.js +28 -23
- package/src/eventDefinitions/ConditionalEventDefinition.js +42 -23
- package/src/eventDefinitions/ErrorEventDefinition.js +47 -34
- package/src/eventDefinitions/EscalationEventDefinition.js +21 -20
- package/src/eventDefinitions/EventDefinitionExecution.js +6 -6
- package/src/eventDefinitions/LinkEventDefinition.js +28 -22
- package/src/eventDefinitions/MessageEventDefinition.js +47 -36
- package/src/eventDefinitions/SignalEventDefinition.js +42 -31
- package/src/eventDefinitions/TerminateEventDefinition.js +4 -4
- package/src/eventDefinitions/TimerEventDefinition.js +56 -57
- package/src/events/BoundaryEvent.js +81 -46
- package/src/events/EndEvent.js +2 -2
- package/src/events/IntermediateCatchEvent.js +8 -4
- package/src/events/IntermediateThrowEvent.js +2 -2
- package/src/events/StartEvent.js +29 -18
- package/src/flows/Association.js +11 -11
- package/src/flows/MessageFlow.js +16 -14
- package/src/flows/SequenceFlow.js +22 -20
- package/src/gateways/EventBasedGateway.js +7 -6
- package/src/gateways/ExclusiveGateway.js +4 -4
- package/src/gateways/InclusiveGateway.js +3 -3
- package/src/gateways/ParallelGateway.js +4 -4
- package/src/getPropertyValue.js +3 -6
- package/src/index.js +3 -3
- package/src/io/BpmnIO.js +5 -6
- package/src/io/EnvironmentDataObject.js +2 -3
- package/src/io/EnvironmentDataStore.js +2 -2
- package/src/io/EnvironmentDataStoreReference.js +2 -2
- package/src/io/InputOutputSpecification.js +60 -54
- package/src/io/Properties.js +45 -33
- package/src/messageHelper.js +16 -23
- package/src/process/Lane.js +3 -3
- package/src/process/Process.js +40 -34
- package/src/process/ProcessExecution.js +122 -78
- package/src/tasks/CallActivity.js +109 -57
- package/src/tasks/LoopCharacteristics.js +30 -18
- package/src/tasks/ReceiveTask.js +59 -38
- package/src/tasks/ScriptTask.js +17 -8
- package/src/tasks/ServiceTask.js +16 -9
- package/src/tasks/SignalTask.js +47 -28
- package/src/tasks/StandardLoopCharacteristics.js +3 -3
- package/src/tasks/SubProcess.js +9 -8
- package/src/tasks/Task.js +4 -3
- package/src/tasks/Transaction.js +1 -1
- package/types/index.d.ts +6 -6
- package/types/types.d.ts +39 -35
- package/CHANGELOG.md +0 -459
- package/src/ExtensionsMapper.js +0 -42
- package/src/iso-duration.js +0 -91
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import getPropertyValue from '../getPropertyValue.js';
|
|
2
|
-
import {brokerSafeId} from '../shared.js';
|
|
3
|
-
import {cloneContent, shiftParent} from '../messageHelper.js';
|
|
2
|
+
import { brokerSafeId } from '../shared.js';
|
|
3
|
+
import { cloneContent, shiftParent } from '../messageHelper.js';
|
|
4
4
|
|
|
5
5
|
const kCompleted = Symbol.for('completed');
|
|
6
6
|
const kMessageQ = Symbol.for('messageQ');
|
|
@@ -9,30 +9,30 @@ const kReferenceElement = Symbol.for('referenceElement');
|
|
|
9
9
|
const kReferenceInfo = Symbol.for('referenceInfo');
|
|
10
10
|
|
|
11
11
|
export default function MessageEventDefinition(activity, eventDefinition) {
|
|
12
|
-
const {id, broker, environment, isThrowing} = activity;
|
|
13
|
-
const {type = 'MessageEventDefinition', behaviour = {}} = eventDefinition;
|
|
12
|
+
const { id, broker, environment, isThrowing } = activity;
|
|
13
|
+
const { type = 'MessageEventDefinition', behaviour = {} } = eventDefinition;
|
|
14
14
|
|
|
15
15
|
this.id = id;
|
|
16
16
|
this.type = type;
|
|
17
17
|
|
|
18
|
-
const reference = this.reference = {
|
|
18
|
+
const reference = (this.reference = {
|
|
19
19
|
name: 'anonymous',
|
|
20
20
|
...behaviour.messageRef,
|
|
21
21
|
referenceType: 'message',
|
|
22
|
-
};
|
|
22
|
+
});
|
|
23
23
|
|
|
24
24
|
this.isThrowing = isThrowing;
|
|
25
25
|
this.activity = activity;
|
|
26
26
|
this.broker = broker;
|
|
27
27
|
this.logger = environment.Logger(type.toLowerCase());
|
|
28
28
|
|
|
29
|
-
const referenceElement = this[kReferenceElement] = reference.id && activity.getActivityById(reference.id);
|
|
29
|
+
const referenceElement = (this[kReferenceElement] = reference.id && activity.getActivityById(reference.id));
|
|
30
30
|
if (!isThrowing) {
|
|
31
31
|
this[kCompleted] = false;
|
|
32
32
|
const referenceId = referenceElement ? referenceElement.id : 'anonymous';
|
|
33
33
|
const messageQueueName = `${reference.referenceType}-${brokerSafeId(id)}-${brokerSafeId(referenceId)}-q`;
|
|
34
|
-
this[kMessageQ] = broker.assertQueue(messageQueueName, {autoDelete: false, durable: true});
|
|
35
|
-
broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, {durable: true});
|
|
34
|
+
this[kMessageQ] = broker.assertQueue(messageQueueName, { autoDelete: false, durable: true });
|
|
35
|
+
broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, { durable: true });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -52,10 +52,10 @@ MessageEventDefinition.prototype.executeCatch = function executeCatch(executeMes
|
|
|
52
52
|
this[kCompleted] = false;
|
|
53
53
|
|
|
54
54
|
const executeContent = executeMessage.content;
|
|
55
|
-
const {executionId, parent} = executeContent;
|
|
55
|
+
const { executionId, parent } = executeContent;
|
|
56
56
|
const parentExecutionId = parent && parent.executionId;
|
|
57
57
|
|
|
58
|
-
const info = this[kReferenceInfo] = this._getReferenceInfo(executeMessage);
|
|
58
|
+
const info = (this[kReferenceInfo] = this._getReferenceInfo(executeMessage));
|
|
59
59
|
this._debug(`expect ${info.description}`);
|
|
60
60
|
|
|
61
61
|
const broker = this.broker;
|
|
@@ -85,7 +85,7 @@ MessageEventDefinition.prototype.executeCatch = function executeCatch(executeMes
|
|
|
85
85
|
|
|
86
86
|
const waitContent = cloneContent(executeContent, {
|
|
87
87
|
executionId: parentExecutionId,
|
|
88
|
-
message: {...info.message},
|
|
88
|
+
message: { ...info.message },
|
|
89
89
|
});
|
|
90
90
|
waitContent.parent = shiftParent(parent);
|
|
91
91
|
|
|
@@ -94,7 +94,7 @@ MessageEventDefinition.prototype.executeCatch = function executeCatch(executeMes
|
|
|
94
94
|
|
|
95
95
|
MessageEventDefinition.prototype.executeThrow = function executeThrow(executeMessage) {
|
|
96
96
|
const executeContent = executeMessage.content;
|
|
97
|
-
const {executionId, parent} = executeContent;
|
|
97
|
+
const { executionId, parent } = executeContent;
|
|
98
98
|
const info = this._getReferenceInfo(executeMessage);
|
|
99
99
|
|
|
100
100
|
this.logger.debug(`<${executionId} (${this.activity.id})> message ${info.description}`);
|
|
@@ -102,12 +102,12 @@ MessageEventDefinition.prototype.executeThrow = function executeThrow(executeMes
|
|
|
102
102
|
const broker = this.broker;
|
|
103
103
|
const throwContent = cloneContent(executeContent, {
|
|
104
104
|
executionId: parent.executionId,
|
|
105
|
-
message: {...executeContent.input, ...info.message},
|
|
105
|
+
message: { ...executeContent.input, ...info.message },
|
|
106
106
|
state: 'throw',
|
|
107
107
|
});
|
|
108
108
|
throwContent.parent = shiftParent(parent);
|
|
109
109
|
|
|
110
|
-
broker.publish('event', 'activity.message', throwContent, {type: 'message', delegate: true});
|
|
110
|
+
broker.publish('event', 'activity.message', throwContent, { type: 'message', delegate: true });
|
|
111
111
|
|
|
112
112
|
return broker.publish('execution', 'execute.completed', cloneContent(executeContent));
|
|
113
113
|
};
|
|
@@ -115,28 +115,33 @@ MessageEventDefinition.prototype.executeThrow = function executeThrow(executeMes
|
|
|
115
115
|
MessageEventDefinition.prototype._onCatchMessage = function onCatchMessage(routingKey, message) {
|
|
116
116
|
if (getPropertyValue(message, 'content.message.id') !== this[kReferenceInfo].message.id) return;
|
|
117
117
|
|
|
118
|
-
const {type, correlationId} = message.properties;
|
|
119
|
-
this.broker.publish(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
118
|
+
const { type, correlationId } = message.properties;
|
|
119
|
+
this.broker.publish(
|
|
120
|
+
'event',
|
|
121
|
+
'activity.consumed',
|
|
122
|
+
cloneContent(this[kExecuteMessage].content, {
|
|
123
|
+
message: { ...message.content.message },
|
|
124
|
+
}),
|
|
125
|
+
{
|
|
126
|
+
correlationId,
|
|
127
|
+
type,
|
|
128
|
+
},
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
this._complete('caught', message.content.message, { correlationId });
|
|
127
132
|
};
|
|
128
133
|
|
|
129
134
|
MessageEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey, message) {
|
|
130
|
-
const {type, correlationId} = message.properties;
|
|
135
|
+
const { type, correlationId } = message.properties;
|
|
131
136
|
switch (type) {
|
|
132
137
|
case 'message':
|
|
133
138
|
case 'signal': {
|
|
134
|
-
return this._complete('got signal with', message.content.message, {correlationId});
|
|
139
|
+
return this._complete('got signal with', message.content.message, { correlationId });
|
|
135
140
|
}
|
|
136
141
|
case 'discard': {
|
|
137
142
|
this[kCompleted] = true;
|
|
138
143
|
this._stop();
|
|
139
|
-
return this.broker.publish('execution', 'execute.discard', cloneContent(this[kExecuteMessage].content), {correlationId});
|
|
144
|
+
return this.broker.publish('execution', 'execute.discard', cloneContent(this[kExecuteMessage].content), { correlationId });
|
|
140
145
|
}
|
|
141
146
|
case 'stop': {
|
|
142
147
|
return this._stop();
|
|
@@ -153,21 +158,27 @@ MessageEventDefinition.prototype._complete = function complete(verb, output, opt
|
|
|
153
158
|
const broker = this.broker;
|
|
154
159
|
const executeContent = this[kExecuteMessage].content;
|
|
155
160
|
const catchContent = cloneContent(executeContent, {
|
|
156
|
-
message: {...output},
|
|
161
|
+
message: { ...output },
|
|
157
162
|
executionId: executeContent.parent.executionId,
|
|
158
163
|
});
|
|
159
164
|
catchContent.parent = shiftParent(executeContent.parent);
|
|
160
165
|
|
|
161
|
-
broker.publish('event', 'activity.catch', catchContent, {type: 'catch'});
|
|
162
|
-
|
|
163
|
-
return broker.publish(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
166
|
+
broker.publish('event', 'activity.catch', catchContent, { type: 'catch' });
|
|
167
|
+
|
|
168
|
+
return broker.publish(
|
|
169
|
+
'execution',
|
|
170
|
+
'execute.completed',
|
|
171
|
+
cloneContent(executeContent, {
|
|
172
|
+
output,
|
|
173
|
+
state: 'catch',
|
|
174
|
+
}),
|
|
175
|
+
options,
|
|
176
|
+
);
|
|
167
177
|
};
|
|
168
178
|
|
|
169
179
|
MessageEventDefinition.prototype._stop = function stop() {
|
|
170
|
-
const broker = this.broker,
|
|
180
|
+
const broker = this.broker,
|
|
181
|
+
executionId = this.executionId;
|
|
171
182
|
broker.cancel(`_api-message-${executionId}`);
|
|
172
183
|
broker.cancel(`_api-${executionId}`);
|
|
173
184
|
broker.cancel(`_api-parent-${executionId}`);
|
|
@@ -179,7 +190,7 @@ MessageEventDefinition.prototype._getReferenceInfo = function getReferenceInfo(m
|
|
|
179
190
|
const referenceElement = this[kReferenceElement];
|
|
180
191
|
if (!referenceElement) {
|
|
181
192
|
return {
|
|
182
|
-
message: {...this.reference},
|
|
193
|
+
message: { ...this.reference },
|
|
183
194
|
description: 'anonymous message',
|
|
184
195
|
};
|
|
185
196
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import getPropertyValue from '../getPropertyValue.js';
|
|
2
|
-
import {brokerSafeId} from '../shared.js';
|
|
3
|
-
import {cloneContent, shiftParent} from '../messageHelper.js';
|
|
2
|
+
import { brokerSafeId } from '../shared.js';
|
|
3
|
+
import { cloneContent, shiftParent } from '../messageHelper.js';
|
|
4
4
|
|
|
5
5
|
const kCompleted = Symbol.for('completed');
|
|
6
6
|
const kMessageQ = Symbol.for('messageQ');
|
|
@@ -9,30 +9,30 @@ const kReferenceElement = Symbol.for('referenceElement');
|
|
|
9
9
|
const kReferenceInfo = Symbol.for('referenceInfo');
|
|
10
10
|
|
|
11
11
|
export default function SignalEventDefinition(activity, eventDefinition) {
|
|
12
|
-
const {id, broker, environment, isStart, isThrowing} = activity;
|
|
13
|
-
const {type, behaviour = {}} = eventDefinition;
|
|
12
|
+
const { id, broker, environment, isStart, isThrowing } = activity;
|
|
13
|
+
const { type, behaviour = {} } = eventDefinition;
|
|
14
14
|
|
|
15
15
|
this.id = id;
|
|
16
16
|
this.type = type;
|
|
17
17
|
|
|
18
|
-
const reference = this.reference = {
|
|
18
|
+
const reference = (this.reference = {
|
|
19
19
|
name: 'anonymous',
|
|
20
20
|
...behaviour.signalRef,
|
|
21
21
|
referenceType: 'signal',
|
|
22
|
-
};
|
|
22
|
+
});
|
|
23
23
|
|
|
24
24
|
this.isThrowing = isThrowing;
|
|
25
25
|
this.activity = activity;
|
|
26
26
|
this.broker = broker;
|
|
27
27
|
this.logger = environment.Logger(type.toLowerCase());
|
|
28
28
|
|
|
29
|
-
const referenceElement = this[kReferenceElement] = reference.id && activity.getActivityById(reference.id);
|
|
29
|
+
const referenceElement = (this[kReferenceElement] = reference.id && activity.getActivityById(reference.id));
|
|
30
30
|
if (!isThrowing && isStart) {
|
|
31
31
|
this[kCompleted] = false;
|
|
32
32
|
const referenceId = referenceElement ? referenceElement.id : 'anonymous';
|
|
33
33
|
const messageQueueName = `${reference.referenceType}-${brokerSafeId(id)}-${brokerSafeId(referenceId)}-q`;
|
|
34
|
-
this[kMessageQ] = broker.assertQueue(messageQueueName, {autoDelete: false, durable: true});
|
|
35
|
-
broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, {durable: true});
|
|
34
|
+
this[kMessageQ] = broker.assertQueue(messageQueueName, { autoDelete: false, durable: true });
|
|
35
|
+
broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, { durable: true });
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -52,10 +52,10 @@ SignalEventDefinition.prototype.executeCatch = function executeCatch(executeMess
|
|
|
52
52
|
this[kCompleted] = false;
|
|
53
53
|
|
|
54
54
|
const executeContent = executeMessage.content;
|
|
55
|
-
const {executionId, parent} = executeContent;
|
|
55
|
+
const { executionId, parent } = executeContent;
|
|
56
56
|
const parentExecutionId = parent && parent.executionId;
|
|
57
57
|
|
|
58
|
-
const info = this[kReferenceInfo] = this._getReferenceInfo(executeMessage);
|
|
58
|
+
const info = (this[kReferenceInfo] = this._getReferenceInfo(executeMessage));
|
|
59
59
|
const broker = this.broker;
|
|
60
60
|
|
|
61
61
|
const onCatchMessage = this._onCatchMessage.bind(this);
|
|
@@ -85,7 +85,7 @@ SignalEventDefinition.prototype.executeCatch = function executeCatch(executeMess
|
|
|
85
85
|
|
|
86
86
|
const waitContent = cloneContent(executeContent, {
|
|
87
87
|
executionId: parent.executionId,
|
|
88
|
-
signal: {...info.message},
|
|
88
|
+
signal: { ...info.message },
|
|
89
89
|
});
|
|
90
90
|
waitContent.parent = shiftParent(parent);
|
|
91
91
|
|
|
@@ -94,7 +94,7 @@ SignalEventDefinition.prototype.executeCatch = function executeCatch(executeMess
|
|
|
94
94
|
|
|
95
95
|
SignalEventDefinition.prototype.executeThrow = function executeThrow(executeMessage) {
|
|
96
96
|
const executeContent = executeMessage.content;
|
|
97
|
-
const {executionId, parent} = executeContent;
|
|
97
|
+
const { executionId, parent } = executeContent;
|
|
98
98
|
|
|
99
99
|
const info = this._getReferenceInfo(executeMessage);
|
|
100
100
|
|
|
@@ -102,13 +102,13 @@ SignalEventDefinition.prototype.executeThrow = function executeThrow(executeMess
|
|
|
102
102
|
|
|
103
103
|
const throwContent = cloneContent(executeContent, {
|
|
104
104
|
executionId: parent.executionId,
|
|
105
|
-
message: {...executeContent.input, ...info.message},
|
|
105
|
+
message: { ...executeContent.input, ...info.message },
|
|
106
106
|
state: 'throw',
|
|
107
107
|
});
|
|
108
108
|
throwContent.parent = shiftParent(parent);
|
|
109
109
|
|
|
110
110
|
const broker = this.broker;
|
|
111
|
-
broker.publish('event', 'activity.signal', throwContent, {type: 'signal'});
|
|
111
|
+
broker.publish('event', 'activity.signal', throwContent, { type: 'signal' });
|
|
112
112
|
|
|
113
113
|
return broker.publish('execution', 'execute.completed', cloneContent(executeContent));
|
|
114
114
|
};
|
|
@@ -119,28 +119,33 @@ SignalEventDefinition.prototype._onCatchMessage = function onCatchMessage(routin
|
|
|
119
119
|
this[kCompleted] = true;
|
|
120
120
|
this._stop();
|
|
121
121
|
|
|
122
|
-
const {type, correlationId} = message.properties;
|
|
123
|
-
this.broker.publish(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
122
|
+
const { type, correlationId } = message.properties;
|
|
123
|
+
this.broker.publish(
|
|
124
|
+
'event',
|
|
125
|
+
'activity.consumed',
|
|
126
|
+
cloneContent(this[kExecuteMessage].content, {
|
|
127
|
+
message: { ...message.content.message },
|
|
128
|
+
}),
|
|
129
|
+
{
|
|
130
|
+
correlationId,
|
|
131
|
+
type,
|
|
132
|
+
},
|
|
133
|
+
);
|
|
129
134
|
|
|
130
135
|
return this._complete(message.content.message, message.properties);
|
|
131
136
|
};
|
|
132
137
|
|
|
133
138
|
SignalEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey, message) {
|
|
134
|
-
const {type, correlationId} = message.properties;
|
|
139
|
+
const { type, correlationId } = message.properties;
|
|
135
140
|
|
|
136
141
|
switch (type) {
|
|
137
142
|
case 'signal': {
|
|
138
|
-
return this._complete(message.content.message, {correlationId});
|
|
143
|
+
return this._complete(message.content.message, { correlationId });
|
|
139
144
|
}
|
|
140
145
|
case 'discard': {
|
|
141
146
|
this[kCompleted] = true;
|
|
142
147
|
this._stop();
|
|
143
|
-
return this.broker.publish('execution', 'execute.discard', cloneContent(this[kExecuteMessage].content), {correlationId});
|
|
148
|
+
return this.broker.publish('execution', 'execute.discard', cloneContent(this[kExecuteMessage].content), { correlationId });
|
|
144
149
|
}
|
|
145
150
|
case 'stop': {
|
|
146
151
|
this._stop();
|
|
@@ -153,14 +158,20 @@ SignalEventDefinition.prototype._complete = function complete(output, options) {
|
|
|
153
158
|
this[kCompleted] = true;
|
|
154
159
|
this._stop();
|
|
155
160
|
this._debug(`signaled with ${this[kReferenceInfo].description}`);
|
|
156
|
-
return this.broker.publish(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
161
|
+
return this.broker.publish(
|
|
162
|
+
'execution',
|
|
163
|
+
'execute.completed',
|
|
164
|
+
cloneContent(this[kExecuteMessage].content, {
|
|
165
|
+
output,
|
|
166
|
+
state: 'signal',
|
|
167
|
+
}),
|
|
168
|
+
options,
|
|
169
|
+
);
|
|
160
170
|
};
|
|
161
171
|
|
|
162
172
|
SignalEventDefinition.prototype._stop = function stop() {
|
|
163
|
-
const broker = this.broker,
|
|
173
|
+
const broker = this.broker,
|
|
174
|
+
executionId = this.executionId;
|
|
164
175
|
broker.cancel(`_api-signal-${executionId}`);
|
|
165
176
|
broker.cancel(`_api-parent-${executionId}`);
|
|
166
177
|
broker.cancel(`_api-${executionId}`);
|
|
@@ -172,7 +183,7 @@ SignalEventDefinition.prototype._getReferenceInfo = function getReferenceInfo(me
|
|
|
172
183
|
const referenceElement = this[kReferenceElement];
|
|
173
184
|
if (!referenceElement) {
|
|
174
185
|
return {
|
|
175
|
-
message: {...this.reference},
|
|
186
|
+
message: { ...this.reference },
|
|
176
187
|
description: 'anonymous signal',
|
|
177
188
|
};
|
|
178
189
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {cloneContent, shiftParent} from '../messageHelper.js';
|
|
1
|
+
import { cloneContent, shiftParent } from '../messageHelper.js';
|
|
2
2
|
|
|
3
3
|
export default function TerminateEventDefinition(activity, eventDefinition) {
|
|
4
|
-
const {id, broker, environment} = activity;
|
|
5
|
-
const {type = 'TerminateEventDefinition'} = eventDefinition;
|
|
4
|
+
const { id, broker, environment } = activity;
|
|
5
|
+
const { type = 'TerminateEventDefinition' } = eventDefinition;
|
|
6
6
|
|
|
7
7
|
this.id = id;
|
|
8
8
|
this.type = type;
|
|
@@ -21,6 +21,6 @@ TerminateEventDefinition.prototype.execute = function execute(executeMessage) {
|
|
|
21
21
|
|
|
22
22
|
this.logger.debug(`<${executeContent.executionId} (${executeContent.id})> terminate`);
|
|
23
23
|
const broker = this.broker;
|
|
24
|
-
broker.publish('event', 'process.terminate', throwContent, {type: 'terminate'});
|
|
24
|
+
broker.publish('event', 'process.terminate', throwContent, { type: 'terminate' });
|
|
25
25
|
broker.publish('execution', 'execute.completed', cloneContent(executeContent));
|
|
26
26
|
};
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import {cloneContent} from '../messageHelper.js';
|
|
2
|
-
import {
|
|
1
|
+
import { cloneContent } from '../messageHelper.js';
|
|
2
|
+
import { ISOInterval, getDate } from '@0dep/piso';
|
|
3
3
|
|
|
4
4
|
const kStopped = Symbol.for('stopped');
|
|
5
5
|
const kTimerContent = Symbol.for('timerContent');
|
|
6
6
|
const kTimer = Symbol.for('timer');
|
|
7
7
|
|
|
8
|
+
const timerTypes = ['timeDuration', 'timeDate', 'timeCycle'];
|
|
9
|
+
|
|
8
10
|
export default function TimerEventDefinition(activity, eventDefinition) {
|
|
9
|
-
const type = this.type = eventDefinition.type || 'TimerEventDefinition';
|
|
11
|
+
const type = (this.type = eventDefinition.type || 'TimerEventDefinition');
|
|
10
12
|
this.activity = activity;
|
|
11
|
-
const environment = this.environment = activity.environment;
|
|
13
|
+
const environment = (this.environment = activity.environment);
|
|
12
14
|
this.eventDefinition = eventDefinition;
|
|
13
15
|
|
|
14
|
-
const {timeDuration, timeCycle, timeDate} = eventDefinition.behaviour || {};
|
|
16
|
+
const { timeDuration, timeCycle, timeDate } = eventDefinition.behaviour || {};
|
|
15
17
|
if (timeDuration) this.timeDuration = timeDuration;
|
|
16
18
|
if (timeCycle) this.timeCycle = timeCycle;
|
|
17
19
|
if (timeDate) this.timeDate = timeDate;
|
|
@@ -43,7 +45,7 @@ Object.defineProperties(TimerEventDefinition.prototype, {
|
|
|
43
45
|
});
|
|
44
46
|
|
|
45
47
|
TimerEventDefinition.prototype.execute = function execute(executeMessage) {
|
|
46
|
-
const {routingKey: executeKey, redelivered: isResumed} = executeMessage.fields;
|
|
48
|
+
const { routingKey: executeKey, redelivered: isResumed } = executeMessage.fields;
|
|
47
49
|
const timer = this[kTimer];
|
|
48
50
|
if (timer && executeKey === 'execute.timer') {
|
|
49
51
|
return;
|
|
@@ -54,23 +56,25 @@ TimerEventDefinition.prototype.execute = function execute(executeMessage) {
|
|
|
54
56
|
|
|
55
57
|
const content = executeMessage.content;
|
|
56
58
|
const executionId = content.executionId;
|
|
57
|
-
const startedAt = this.startedAt = 'startedAt' in content ? new Date(content.startedAt) : new Date();
|
|
59
|
+
const startedAt = (this.startedAt = 'startedAt' in content ? new Date(content.startedAt) : new Date());
|
|
58
60
|
|
|
59
61
|
const resolvedTimer = this._getTimers(executeMessage);
|
|
60
|
-
const timerContent = this[kTimerContent] = cloneContent(content, {
|
|
62
|
+
const timerContent = (this[kTimerContent] = cloneContent(content, {
|
|
61
63
|
...resolvedTimer,
|
|
62
|
-
...(isResumed && {isResumed}),
|
|
64
|
+
...(isResumed && { isResumed }),
|
|
63
65
|
startedAt,
|
|
64
66
|
state: 'timer',
|
|
65
|
-
});
|
|
67
|
+
}));
|
|
66
68
|
|
|
67
69
|
const broker = this.broker;
|
|
68
70
|
broker.subscribeTmp('api', `activity.#.${executionId}`, this._onApiMessage.bind(this), {
|
|
69
|
-
noAck: true,
|
|
71
|
+
noAck: true,
|
|
72
|
+
consumerTag: `_api-${executionId}`,
|
|
70
73
|
priority: 400,
|
|
71
74
|
});
|
|
72
75
|
broker.subscribeTmp('api', '#.cancel.*', this._onDelegatedApiMessage.bind(this), {
|
|
73
|
-
noAck: true,
|
|
76
|
+
noAck: true,
|
|
77
|
+
consumerTag: `_api-delegated-${executionId}`,
|
|
74
78
|
});
|
|
75
79
|
|
|
76
80
|
broker.publish('execution', 'execute.timer', cloneContent(timerContent));
|
|
@@ -78,7 +82,6 @@ TimerEventDefinition.prototype.execute = function execute(executeMessage) {
|
|
|
78
82
|
|
|
79
83
|
if (this.stopped) return;
|
|
80
84
|
|
|
81
|
-
if (timerContent.timeout === undefined) return this._debug(`waiting for ${timerContent.timerType || 'signal'}`);
|
|
82
85
|
if (timerContent.timeout <= 0) return this._completed();
|
|
83
86
|
|
|
84
87
|
const timers = this.environment.timers.register(timerContent);
|
|
@@ -106,14 +109,14 @@ TimerEventDefinition.prototype._completed = function completed(completeContent,
|
|
|
106
109
|
this._debug(`completed in ${runningTime}ms`);
|
|
107
110
|
|
|
108
111
|
const timerContent = this[kTimerContent];
|
|
109
|
-
const content = {stoppedAt, runningTime, state: 'timeout', ...completeContent};
|
|
112
|
+
const content = { stoppedAt, runningTime, state: 'timeout', ...completeContent };
|
|
110
113
|
|
|
111
114
|
const broker = this.broker;
|
|
112
115
|
broker.publish('event', 'activity.timeout', cloneContent(timerContent, content), options);
|
|
113
116
|
|
|
114
117
|
if (timerContent.repeat > 1) {
|
|
115
118
|
const repeat = timerContent.repeat - 1;
|
|
116
|
-
broker.publish('execution', 'execute.repeat', cloneContent(timerContent, {...content, repeat}), options);
|
|
119
|
+
broker.publish('execution', 'execute.repeat', cloneContent(timerContent, { ...content, repeat }), options);
|
|
117
120
|
}
|
|
118
121
|
|
|
119
122
|
broker.publish('execution', 'execute.completed', cloneContent(timerContent, content), options);
|
|
@@ -125,33 +128,41 @@ TimerEventDefinition.prototype._onDelegatedApiMessage = function onDelegatedApiM
|
|
|
125
128
|
const content = message.content;
|
|
126
129
|
if (!content.message) return;
|
|
127
130
|
|
|
128
|
-
const {id: signalId, executionId: signalExecutionId} = content.message;
|
|
131
|
+
const { id: signalId, executionId: signalExecutionId } = content.message;
|
|
129
132
|
|
|
130
133
|
const executionId = this.executionId;
|
|
131
134
|
const id = this.activity.id;
|
|
132
135
|
if (signalId !== id && signalExecutionId !== executionId) return;
|
|
133
136
|
if (signalExecutionId && signalId === id && signalExecutionId !== executionId) return;
|
|
134
137
|
|
|
135
|
-
const {type, correlationId} = message.properties;
|
|
136
|
-
this.broker.publish(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
const { type, correlationId } = message.properties;
|
|
139
|
+
this.broker.publish(
|
|
140
|
+
'event',
|
|
141
|
+
'activity.consumed',
|
|
142
|
+
cloneContent(this[kTimerContent], {
|
|
143
|
+
message: {
|
|
144
|
+
...content.message,
|
|
145
|
+
},
|
|
146
|
+
}),
|
|
147
|
+
{ correlationId, type },
|
|
148
|
+
);
|
|
141
149
|
|
|
142
150
|
return this._onApiMessage(routingKey, message);
|
|
143
151
|
};
|
|
144
152
|
|
|
145
153
|
TimerEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey, message) {
|
|
146
|
-
const {type: messageType, correlationId} = message.properties;
|
|
154
|
+
const { type: messageType, correlationId } = message.properties;
|
|
147
155
|
|
|
148
156
|
switch (messageType) {
|
|
149
157
|
case 'cancel': {
|
|
150
158
|
this._stop();
|
|
151
|
-
return this._completed(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
159
|
+
return this._completed(
|
|
160
|
+
{
|
|
161
|
+
state: 'cancel',
|
|
162
|
+
...(message.content.message && { message: message.content.message }),
|
|
163
|
+
},
|
|
164
|
+
{ correlationId },
|
|
165
|
+
);
|
|
155
166
|
}
|
|
156
167
|
case 'stop': {
|
|
157
168
|
this._stop();
|
|
@@ -160,7 +171,9 @@ TimerEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey,
|
|
|
160
171
|
case 'discard': {
|
|
161
172
|
this._stop();
|
|
162
173
|
this._debug('discarded');
|
|
163
|
-
return this.broker.publish('execution', 'execute.discard', cloneContent(this[kTimerContent], {state: 'discard'}), {
|
|
174
|
+
return this.broker.publish('execution', 'execute.discard', cloneContent(this[kTimerContent], { state: 'discard' }), {
|
|
175
|
+
correlationId,
|
|
176
|
+
});
|
|
164
177
|
}
|
|
165
178
|
}
|
|
166
179
|
};
|
|
@@ -176,23 +189,19 @@ TimerEventDefinition.prototype._stop = function stop() {
|
|
|
176
189
|
|
|
177
190
|
TimerEventDefinition.prototype.parse = function parse(timerType, value) {
|
|
178
191
|
let repeat, delay, expireAt;
|
|
192
|
+
const now = new Date();
|
|
179
193
|
switch (timerType) {
|
|
180
194
|
case 'timeCycle':
|
|
181
195
|
case 'timeDuration': {
|
|
182
|
-
const parsed =
|
|
196
|
+
const parsed = new ISOInterval(value).parse();
|
|
183
197
|
if (parsed.repeat) repeat = parsed.repeat;
|
|
184
|
-
|
|
185
|
-
|
|
198
|
+
expireAt = parsed.getExpireAt(now, now);
|
|
199
|
+
delay = expireAt.getTime() - now.getTime();
|
|
186
200
|
break;
|
|
187
201
|
}
|
|
188
202
|
case 'timeDate': {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
expireAt = new Date(ms);
|
|
192
|
-
delay = Date.now() - expireAt;
|
|
193
|
-
} else {
|
|
194
|
-
throw new TypeError(`invalid timeDate >${value}<`);
|
|
195
|
-
}
|
|
203
|
+
expireAt = getDate(value);
|
|
204
|
+
delay = now.getTime() - expireAt;
|
|
196
205
|
break;
|
|
197
206
|
}
|
|
198
207
|
}
|
|
@@ -208,32 +217,26 @@ TimerEventDefinition.prototype._getTimers = function getTimers(executeMessage) {
|
|
|
208
217
|
const content = executeMessage.content;
|
|
209
218
|
|
|
210
219
|
const result = {
|
|
211
|
-
...('expireAt' in content && {expireAt: new Date(content.expireAt)}),
|
|
220
|
+
...('expireAt' in content && { expireAt: new Date(content.expireAt) }),
|
|
212
221
|
};
|
|
213
222
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if (
|
|
217
|
-
else if (t in this) result[t] = this.environment.resolveExpression(this[t], executeMessage);
|
|
223
|
+
for (const timerType of timerTypes) {
|
|
224
|
+
if (timerType in content) result[timerType] = content[timerType];
|
|
225
|
+
else if (timerType in this) result[timerType] = this.environment.resolveExpression(this[timerType], executeMessage);
|
|
218
226
|
else continue;
|
|
219
227
|
|
|
220
228
|
let expireAtDate, repeat;
|
|
221
|
-
const timerStr = result[
|
|
229
|
+
const timerStr = result[timerType];
|
|
222
230
|
if (timerStr) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
expireAtDate = parsedExpireAt;
|
|
227
|
-
} catch (err) {
|
|
228
|
-
parseErr = err;
|
|
229
|
-
}
|
|
231
|
+
const { repeat: parsedRepeat, expireAt: parsedExpireAt } = this.parse(timerType, timerStr);
|
|
232
|
+
repeat = parsedRepeat;
|
|
233
|
+
expireAtDate = parsedExpireAt;
|
|
230
234
|
} else {
|
|
231
235
|
expireAtDate = new Date();
|
|
232
236
|
}
|
|
233
237
|
|
|
234
|
-
if (!expireAtDate) continue;
|
|
235
238
|
if (!('expireAt' in result) || result.expireAt > expireAtDate) {
|
|
236
|
-
result.timerType =
|
|
239
|
+
result.timerType = timerType;
|
|
237
240
|
result.expireAt = expireAtDate;
|
|
238
241
|
result.repeat = repeat;
|
|
239
242
|
}
|
|
@@ -247,10 +250,6 @@ TimerEventDefinition.prototype._getTimers = function getTimers(executeMessage) {
|
|
|
247
250
|
result.timeout = 0;
|
|
248
251
|
}
|
|
249
252
|
|
|
250
|
-
if (!('timeout' in result) && parseErr) {
|
|
251
|
-
this.logger.warn(`<${this.activity.id}> failed to parse timer: ${parseErr.message}`);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
253
|
if (content.inbound && 'repeat' in content.inbound[0]) {
|
|
255
254
|
result.repeat = content.inbound[0].repeat;
|
|
256
255
|
}
|