bpmn-elements 9.2.0 → 10.1.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 +13 -0
- package/README.md +4 -0
- package/dist/Context.js +21 -4
- package/dist/Environment.js +1 -1
- package/dist/Timers.js +63 -43
- package/dist/activity/Activity.js +17 -1
- package/dist/definition/DefinitionExecution.js +14 -10
- package/dist/eventDefinitions/TimerEventDefinition.js +51 -41
- package/dist/index.js +19 -0
- package/dist/iso-duration.js +88 -0
- package/dist/process/Lane.js +38 -0
- package/dist/process/Process.js +16 -0
- package/dist/tasks/SubProcess.js +2 -2
- package/package.json +13 -13
- package/src/Context.js +27 -4
- package/src/Environment.js +1 -1
- package/src/Timers.js +71 -40
- package/src/activity/Activity.js +18 -0
- package/src/definition/DefinitionExecution.js +11 -15
- package/src/eventDefinitions/TimerEventDefinition.js +49 -40
- package/src/index.js +6 -0
- package/src/iso-duration.js +91 -0
- package/src/process/Lane.js +27 -0
- package/src/process/Process.js +18 -0
- package/src/tasks/SubProcess.js +2 -2
- package/types/index.d.ts +117 -8
package/dist/process/Process.js
CHANGED
|
@@ -17,6 +17,7 @@ const kCounters = Symbol.for('counters');
|
|
|
17
17
|
const kExec = Symbol.for('execution');
|
|
18
18
|
const kExecuteMessage = Symbol.for('executeMessage');
|
|
19
19
|
const kExtensions = Symbol.for('extensions');
|
|
20
|
+
const kLanes = Symbol.for('lanes');
|
|
20
21
|
const kMessageHandlers = Symbol.for('messageHandlers');
|
|
21
22
|
const kStateMessage = Symbol.for('stateMessage');
|
|
22
23
|
const kStatus = Symbol.for('status');
|
|
@@ -66,6 +67,9 @@ function Process(processDef, context) {
|
|
|
66
67
|
onExecutionMessage: this._onExecutionMessage.bind(this)
|
|
67
68
|
};
|
|
68
69
|
this.logger = environment.Logger(type.toLowerCase());
|
|
70
|
+
if (behaviour.lanes) {
|
|
71
|
+
this[kLanes] = behaviour.lanes.map(lane => new lane.Behaviour(this, lane));
|
|
72
|
+
}
|
|
69
73
|
this[kExtensions] = context.loadExtensions(this);
|
|
70
74
|
}
|
|
71
75
|
Object.defineProperty(Process.prototype, 'counters', {
|
|
@@ -76,6 +80,13 @@ Object.defineProperty(Process.prototype, 'counters', {
|
|
|
76
80
|
};
|
|
77
81
|
}
|
|
78
82
|
});
|
|
83
|
+
Object.defineProperty(Process.prototype, 'lanes', {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
get() {
|
|
86
|
+
const lanes = this[kLanes];
|
|
87
|
+
return lanes && lanes.slice();
|
|
88
|
+
}
|
|
89
|
+
});
|
|
79
90
|
Object.defineProperty(Process.prototype, 'extensions', {
|
|
80
91
|
enumerable: true,
|
|
81
92
|
get() {
|
|
@@ -404,6 +415,11 @@ Process.prototype.getSequenceFlows = function getSequenceFlows() {
|
|
|
404
415
|
if (execution) return execution.getSequenceFlows();
|
|
405
416
|
return this.context.getSequenceFlows();
|
|
406
417
|
};
|
|
418
|
+
Process.prototype.getLaneById = function getLaneById(laneId) {
|
|
419
|
+
const lanes = this[kLanes];
|
|
420
|
+
if (!lanes) return;
|
|
421
|
+
return lanes.find(lane => lane.id === laneId);
|
|
422
|
+
};
|
|
407
423
|
Process.prototype.getPostponed = function getPostponed(...args) {
|
|
408
424
|
const execution = this.execution;
|
|
409
425
|
if (!execution) return [];
|
package/dist/tasks/SubProcess.js
CHANGED
|
@@ -135,7 +135,7 @@ SubProcessBehaviour.prototype.recover = function recover(state) {
|
|
|
135
135
|
executions.splice(0);
|
|
136
136
|
}
|
|
137
137
|
const subEnvironment = this.environment.clone().recover(state.environment);
|
|
138
|
-
const subContext = this.context.clone(subEnvironment);
|
|
138
|
+
const subContext = this.context.clone(subEnvironment, this.activity);
|
|
139
139
|
const execution = new _ProcessExecution.default(this.activity, subContext).recover(state);
|
|
140
140
|
executions.push(execution);
|
|
141
141
|
return execution;
|
|
@@ -168,7 +168,7 @@ SubProcessBehaviour.prototype._upsertExecution = function upsertExecution(execut
|
|
|
168
168
|
return execution;
|
|
169
169
|
}
|
|
170
170
|
const subEnvironment = this.environment.clone();
|
|
171
|
-
const subContext = this.context.clone(subEnvironment);
|
|
171
|
+
const subContext = this.context.clone(subEnvironment, this.activity);
|
|
172
172
|
execution = new _ProcessExecution.default(this.activity, subContext);
|
|
173
173
|
this[kExecutions].push(execution);
|
|
174
174
|
this._addListeners(execution, executionId);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bpmn-elements",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "Executable workflow elements based on BPMN 2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
},
|
|
14
14
|
"sideEffects": false,
|
|
15
15
|
"scripts": {
|
|
16
|
-
"test": "mocha -R
|
|
16
|
+
"test": "mocha -R @bonniernews/hot-bev -p -t 2000",
|
|
17
17
|
"posttest": "npm run lint && npm run dist",
|
|
18
18
|
"lint": "eslint . --cache",
|
|
19
19
|
"prepack": "npm run dist",
|
|
20
|
-
"cov:html": "c8 -r html -r text mocha -R
|
|
20
|
+
"cov:html": "c8 -r html -r text mocha -R @bonniernews/hot-bev -p -t 2000",
|
|
21
21
|
"test:lcov": "c8 -r lcov mocha && npm run lint",
|
|
22
22
|
"dist": "babel src -d dist/"
|
|
23
23
|
},
|
|
@@ -45,26 +45,26 @@
|
|
|
45
45
|
],
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@aircall/expression-parser": "^1.0.4",
|
|
48
|
-
"@babel/cli": "^7.
|
|
49
|
-
"@babel/core": "^7.
|
|
50
|
-
"@babel/preset-env": "^7.
|
|
51
|
-
"@babel/register": "^7.
|
|
48
|
+
"@babel/cli": "^7.22.5",
|
|
49
|
+
"@babel/core": "^7.22.5",
|
|
50
|
+
"@babel/preset-env": "^7.22.5",
|
|
51
|
+
"@babel/register": "^7.22.5",
|
|
52
|
+
"@bonniernews/hot-bev": "^0.4.0",
|
|
52
53
|
"bpmn-moddle": "^8.0.1",
|
|
53
|
-
"c8": "^7.
|
|
54
|
+
"c8": "^7.14.0",
|
|
54
55
|
"camunda-bpmn-moddle": "^7.0.1",
|
|
55
56
|
"chai": "^4.3.7",
|
|
56
57
|
"chronokinesis": "^5.0.2",
|
|
57
58
|
"debug": "^4.3.4",
|
|
58
|
-
"eslint": "^8.
|
|
59
|
+
"eslint": "^8.42.0",
|
|
59
60
|
"eslint-plugin-import": "^2.27.5",
|
|
60
|
-
"got": "^12.6.
|
|
61
|
+
"got": "^12.6.1",
|
|
61
62
|
"mocha": "^10.1.0",
|
|
62
63
|
"mocha-cakes-2": "^3.3.0",
|
|
63
|
-
"moddle-context-serializer": "^
|
|
64
|
-
"nock": "^13.
|
|
64
|
+
"moddle-context-serializer": "^4.0.0",
|
|
65
|
+
"nock": "^13.3.1"
|
|
65
66
|
},
|
|
66
67
|
"dependencies": {
|
|
67
|
-
"iso8601-duration": "^2.1.1",
|
|
68
68
|
"smqp": "^7.1.4"
|
|
69
69
|
}
|
|
70
70
|
}
|
package/src/Context.js
CHANGED
|
@@ -3,12 +3,14 @@ import Environment from './Environment.js';
|
|
|
3
3
|
import ExtensionsMapper from './ExtensionsMapper.js';
|
|
4
4
|
import {getUniqueId} from './shared.js';
|
|
5
5
|
|
|
6
|
+
const kOwner = Symbol.for('owner');
|
|
7
|
+
|
|
6
8
|
export default function Context(definitionContext, environment) {
|
|
7
9
|
environment = environment ? environment.clone() : new Environment();
|
|
8
10
|
return new ContextInstance(definitionContext, environment);
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
function ContextInstance(definitionContext, environment) {
|
|
13
|
+
function ContextInstance(definitionContext, environment, owner) {
|
|
12
14
|
const {id = 'Def', name, type = 'context'} = definitionContext;
|
|
13
15
|
const sid = getUniqueId(id);
|
|
14
16
|
this.id = id;
|
|
@@ -29,8 +31,15 @@ function ContextInstance(definitionContext, environment) {
|
|
|
29
31
|
sequenceFlowRefs: {},
|
|
30
32
|
sequenceFlows: [],
|
|
31
33
|
};
|
|
34
|
+
this[kOwner] = owner;
|
|
32
35
|
}
|
|
33
36
|
|
|
37
|
+
Object.defineProperty(ContextInstance.prototype, 'owner', {
|
|
38
|
+
get() {
|
|
39
|
+
return this[kOwner];
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
34
43
|
ContextInstance.prototype.getActivityById = function getActivityById(activityId) {
|
|
35
44
|
const activityInstance = this.refs.activityRefs[activityId];
|
|
36
45
|
if (activityInstance) return activityInstance;
|
|
@@ -106,8 +115,8 @@ ContextInstance.prototype.upsertAssociation = function upsertAssociation(associa
|
|
|
106
115
|
return instance;
|
|
107
116
|
};
|
|
108
117
|
|
|
109
|
-
ContextInstance.prototype.clone = function clone(newEnvironment) {
|
|
110
|
-
return new ContextInstance(this.definitionContext, newEnvironment || this.environment);
|
|
118
|
+
ContextInstance.prototype.clone = function clone(newEnvironment, newOwner) {
|
|
119
|
+
return new ContextInstance(this.definitionContext, newEnvironment || this.environment, newOwner);
|
|
111
120
|
};
|
|
112
121
|
|
|
113
122
|
ContextInstance.prototype.getProcessById = function getProcessById(processId) {
|
|
@@ -120,6 +129,8 @@ ContextInstance.prototype.getProcessById = function getProcessById(processId) {
|
|
|
120
129
|
|
|
121
130
|
const bpContext = this.clone(this.environment.clone());
|
|
122
131
|
bp = refs[processId] = new processDefinition.Behaviour(processDefinition, bpContext);
|
|
132
|
+
bpContext[kOwner] = bp;
|
|
133
|
+
|
|
123
134
|
this.refs.processes.push(bp);
|
|
124
135
|
|
|
125
136
|
return bp;
|
|
@@ -128,7 +139,11 @@ ContextInstance.prototype.getProcessById = function getProcessById(processId) {
|
|
|
128
139
|
ContextInstance.prototype.getNewProcessById = function getNewProcessById(processId) {
|
|
129
140
|
if (!this.getProcessById(processId)) return null;
|
|
130
141
|
const bpDef = this.definitionContext.getProcessById(processId);
|
|
131
|
-
|
|
142
|
+
|
|
143
|
+
const bpContext = this.clone(this.environment.clone());
|
|
144
|
+
const bp = new bpDef.Behaviour(bpDef, bpContext);
|
|
145
|
+
bpContext[kOwner] = bp;
|
|
146
|
+
|
|
132
147
|
return bp;
|
|
133
148
|
};
|
|
134
149
|
|
|
@@ -201,3 +216,11 @@ ContextInstance.prototype.loadExtensions = function loadExtensions(activity) {
|
|
|
201
216
|
if (!extensions.extensions.length) return;
|
|
202
217
|
return extensions;
|
|
203
218
|
};
|
|
219
|
+
|
|
220
|
+
ContextInstance.prototype.getActivityParentById = function getActivityParentById(activityId) {
|
|
221
|
+
const owner = this[kOwner];
|
|
222
|
+
if (owner) return owner;
|
|
223
|
+
const activity = this.getActivityById(activityId);
|
|
224
|
+
const parentId = activity.parent.id;
|
|
225
|
+
return this.getProcessById(parentId) || this.getActivityById(parentId);
|
|
226
|
+
};
|
package/src/Environment.js
CHANGED
|
@@ -24,7 +24,7 @@ export default function Environment(options = {}) {
|
|
|
24
24
|
this.extensions = options.extensions;
|
|
25
25
|
this.output = options.output || {};
|
|
26
26
|
this.scripts = options.scripts || IScripts();
|
|
27
|
-
this.timers = options.timers || Timers();
|
|
27
|
+
this.timers = options.timers || new Timers();
|
|
28
28
|
this.settings = {...options.settings};
|
|
29
29
|
this.Logger = options.Logger || DummyLogger;
|
|
30
30
|
this[kServices] = options.services || {};
|
package/src/Timers.js
CHANGED
|
@@ -1,56 +1,87 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const kExecuting = Symbol.for('executing');
|
|
2
|
+
const kTimerApi = Symbol.for('timers api');
|
|
3
|
+
|
|
4
|
+
const MAX_DELAY = 2147483647;
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
export function Timers(options) {
|
|
7
|
+
this.count = 0;
|
|
8
|
+
this.options = {
|
|
6
9
|
setTimeout,
|
|
7
10
|
clearTimeout,
|
|
8
11
|
...options,
|
|
9
12
|
};
|
|
13
|
+
this[kExecuting] = [];
|
|
14
|
+
this.setTimeout = this.setTimeout.bind(this);
|
|
15
|
+
this.clearTimeout = this.clearTimeout.bind(this);
|
|
16
|
+
}
|
|
10
17
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
setTimeout: wrappedSetTimeout,
|
|
17
|
-
clearTimeout: wrappedClearTimeout,
|
|
18
|
-
};
|
|
18
|
+
Object.defineProperty(Timers.prototype, 'executing', {
|
|
19
|
+
get() {
|
|
20
|
+
return this[kExecuting].slice();
|
|
21
|
+
},
|
|
22
|
+
});
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
Timers.prototype.register = function register(owner) {
|
|
25
|
+
return new RegisteredTimers(this, owner);
|
|
26
|
+
};
|
|
21
27
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
clearTimeout: timersApi.clearTimeout,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
+
Timers.prototype.setTimeout = function wrappedSetTimeout(callback, delay, ...args) {
|
|
29
|
+
return this._setTimeout(null, callback, delay, ...args);
|
|
30
|
+
};
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
Timers.prototype.clearTimeout = function wrappedClearTimeout(ref) {
|
|
33
|
+
const executing = this[kExecuting];
|
|
34
|
+
const idx = executing.indexOf(ref);
|
|
35
|
+
if (idx > -1) {
|
|
36
|
+
executing.splice(idx, 1);
|
|
37
|
+
ref.timerRef = this.options.clearTimeout(ref.timerRef);
|
|
38
|
+
return;
|
|
33
39
|
}
|
|
40
|
+
return this.options.clearTimeout(ref);
|
|
41
|
+
};
|
|
34
42
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
function onTimeout(...rargs) {
|
|
42
|
-
const idx = executing.indexOf(ref);
|
|
43
|
-
if (idx > -1) executing.splice(idx, 1);
|
|
44
|
-
return callback(...rargs);
|
|
45
|
-
}
|
|
43
|
+
Timers.prototype._setTimeout = function setTimeout(owner, callback, delay, ...args) {
|
|
44
|
+
const executing = this[kExecuting];
|
|
45
|
+
const ref = this._getReference(owner, callback, delay, args);
|
|
46
|
+
executing.push(ref);
|
|
47
|
+
if (delay < MAX_DELAY) {
|
|
48
|
+
ref.timerRef = this.options.setTimeout(onTimeout, ref.delay, ...ref.args);
|
|
46
49
|
}
|
|
50
|
+
return ref;
|
|
47
51
|
|
|
48
|
-
function
|
|
52
|
+
function onTimeout(...rargs) {
|
|
49
53
|
const idx = executing.indexOf(ref);
|
|
50
|
-
if (idx > -1)
|
|
51
|
-
|
|
52
|
-
return options.clearTimeout.call(null, ref.timerRef);
|
|
53
|
-
}
|
|
54
|
-
return options.clearTimeout.call(null, ref);
|
|
54
|
+
if (idx > -1) executing.splice(idx, 1);
|
|
55
|
+
return callback(...rargs);
|
|
55
56
|
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
Timers.prototype._getReference = function getReference(owner, callback, delay, args) {
|
|
60
|
+
return new Timer(owner, `timer_${this.count++}`, callback, delay, args);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
function RegisteredTimers(timersApi, owner) {
|
|
64
|
+
this[kTimerApi] = timersApi;
|
|
65
|
+
this.owner = owner;
|
|
66
|
+
this.setTimeout = this.setTimeout.bind(this);
|
|
67
|
+
this.clearTimeout = this.clearTimeout.bind(this);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
RegisteredTimers.prototype.setTimeout = function registeredSetTimeout(callback, delay, ...args) {
|
|
71
|
+
const timersApi = this[kTimerApi];
|
|
72
|
+
return timersApi._setTimeout(this.owner, callback, delay, ...args);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
RegisteredTimers.prototype.clearTimeout = function registeredClearTimeout(ref) {
|
|
76
|
+
this[kTimerApi].clearTimeout(ref);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
function Timer(owner, timerId, callback, delay, args) {
|
|
80
|
+
this.callback = callback;
|
|
81
|
+
this.delay = delay;
|
|
82
|
+
this.args = args;
|
|
83
|
+
this.owner = owner;
|
|
84
|
+
this.timerId = timerId;
|
|
85
|
+
this.expireAt = new Date(Date.now() + delay);
|
|
86
|
+
this.timerRef = null;
|
|
56
87
|
}
|
package/src/activity/Activity.js
CHANGED
|
@@ -87,6 +87,7 @@ function Activity(Behaviour, activityDef, context) {
|
|
|
87
87
|
isTransaction: activityDef.isTransaction,
|
|
88
88
|
isParallelJoin,
|
|
89
89
|
isThrowing: activityDef.isThrowing,
|
|
90
|
+
lane: activityDef.lane && activityDef.lane.id,
|
|
90
91
|
};
|
|
91
92
|
this[kExec] = {};
|
|
92
93
|
|
|
@@ -235,6 +236,16 @@ Object.defineProperty(Activity.prototype, 'attachedTo', {
|
|
|
235
236
|
},
|
|
236
237
|
});
|
|
237
238
|
|
|
239
|
+
Object.defineProperty(Activity.prototype, 'lane', {
|
|
240
|
+
enumerable: true,
|
|
241
|
+
get() {
|
|
242
|
+
const laneId = this[kFlags].lane;
|
|
243
|
+
if (!laneId) return undefined;
|
|
244
|
+
const parent = this.parentElement;
|
|
245
|
+
return parent.getLaneById && parent.getLaneById(laneId);
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
|
|
238
249
|
Object.defineProperty(Activity.prototype, 'eventDefinitions', {
|
|
239
250
|
enumerable: true,
|
|
240
251
|
get() {
|
|
@@ -242,6 +253,13 @@ Object.defineProperty(Activity.prototype, 'eventDefinitions', {
|
|
|
242
253
|
},
|
|
243
254
|
});
|
|
244
255
|
|
|
256
|
+
Object.defineProperty(Activity.prototype, 'parentElement', {
|
|
257
|
+
enumerable: true,
|
|
258
|
+
get() {
|
|
259
|
+
return this.context.getActivityParentById(this.id);
|
|
260
|
+
},
|
|
261
|
+
});
|
|
262
|
+
|
|
245
263
|
Activity.prototype.activate = function activate() {
|
|
246
264
|
this[kActivated] = true;
|
|
247
265
|
this.addInboundListeners();
|
|
@@ -322,32 +322,29 @@ DefinitionExecution.prototype._activate = function activate(processList) {
|
|
|
322
322
|
|
|
323
323
|
DefinitionExecution.prototype._activateProcess = function activateProcess(bp) {
|
|
324
324
|
const handlers = this[kMessageHandlers];
|
|
325
|
+
const broker = bp.broker;
|
|
325
326
|
|
|
326
|
-
|
|
327
|
+
broker.subscribeTmp('message', 'message.outbound', handlers.onMessageOutbound, {
|
|
327
328
|
noAck: true,
|
|
328
329
|
consumerTag: '_definition-outbound-message-consumer',
|
|
329
330
|
});
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
consumerTag: '_definition-message-consumer',
|
|
338
|
-
priority: 200,
|
|
339
|
-
});
|
|
340
|
-
bp.broker.subscribeTmp('event', 'activity.call', handlers.onCallActivity, {
|
|
331
|
+
|
|
332
|
+
const delegateEventQ = broker.assertQueue('_delegate-event-q', {autoDelete: false, durable: false});
|
|
333
|
+
delegateEventQ.consume(handlers.onDelegateMessage, {noAck: true, consumerTag: '_definition-signal-consumer'});
|
|
334
|
+
broker.bindQueue('_delegate-event-q', 'event', 'activity.signal', {priority: 200});
|
|
335
|
+
broker.bindQueue('_delegate-event-q', 'event', 'activity.message', {priority: 200});
|
|
336
|
+
|
|
337
|
+
broker.subscribeTmp('event', 'activity.call', handlers.onCallActivity, {
|
|
341
338
|
noAck: true,
|
|
342
339
|
consumerTag: '_definition-call-consumer',
|
|
343
340
|
priority: 200,
|
|
344
341
|
});
|
|
345
|
-
|
|
342
|
+
broker.subscribeTmp('event', 'activity.call.cancel', handlers.onCancelCallActivity, {
|
|
346
343
|
noAck: true,
|
|
347
344
|
consumerTag: '_definition-call-cancel-consumer',
|
|
348
345
|
priority: 200,
|
|
349
346
|
});
|
|
350
|
-
|
|
347
|
+
broker.subscribeTmp('event', '#', handlers.onChildEvent, {
|
|
351
348
|
noAck: true,
|
|
352
349
|
consumerTag: '_definition-activity-consumer',
|
|
353
350
|
priority: 100,
|
|
@@ -383,7 +380,6 @@ DefinitionExecution.prototype._deactivateProcess = function deactivateProcess(bp
|
|
|
383
380
|
bp.broker.cancel('_definition-outbound-message-consumer');
|
|
384
381
|
bp.broker.cancel('_definition-activity-consumer');
|
|
385
382
|
bp.broker.cancel('_definition-signal-consumer');
|
|
386
|
-
bp.broker.cancel('_definition-message-consumer');
|
|
387
383
|
bp.broker.cancel('_definition-call-consumer');
|
|
388
384
|
bp.broker.cancel('_definition-call-cancel-consumer');
|
|
389
385
|
};
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import {cloneContent} from '../messageHelper.js';
|
|
2
|
-
import {toSeconds, parse} from '
|
|
2
|
+
import {toSeconds, parse as parseIsoDuration} from '../iso-duration.js';
|
|
3
3
|
|
|
4
4
|
const kStopped = Symbol.for('stopped');
|
|
5
5
|
const kTimerContent = Symbol.for('timerContent');
|
|
6
6
|
const kTimer = Symbol.for('timer');
|
|
7
|
-
const repeatPattern = /^\s*R(\d+)\//;
|
|
8
7
|
|
|
9
8
|
export default function TimerEventDefinition(activity, eventDefinition) {
|
|
10
|
-
const type = this.type = eventDefinition.type || 'TimerEventDefinition
|
|
9
|
+
const type = this.type = eventDefinition.type || 'TimerEventDefinition';
|
|
11
10
|
this.activity = activity;
|
|
12
11
|
const environment = this.environment = activity.environment;
|
|
13
12
|
this.eventDefinition = eventDefinition;
|
|
@@ -85,12 +84,14 @@ TimerEventDefinition.prototype.execute = function execute(executeMessage) {
|
|
|
85
84
|
if (timerContent.timeout <= 0) return this._completed();
|
|
86
85
|
|
|
87
86
|
const timers = this.environment.timers.register(timerContent);
|
|
88
|
-
|
|
87
|
+
const delay = timerContent.timeout;
|
|
88
|
+
this[kTimer] = timers.setTimeout(this._completed.bind(this), delay, {
|
|
89
89
|
id: content.id,
|
|
90
90
|
type: this.type,
|
|
91
91
|
executionId,
|
|
92
92
|
state: 'timeout',
|
|
93
93
|
});
|
|
94
|
+
this._debug(`set timeout with delay ${delay}`);
|
|
94
95
|
};
|
|
95
96
|
|
|
96
97
|
TimerEventDefinition.prototype.stop = function stopTimer() {
|
|
@@ -175,14 +176,44 @@ TimerEventDefinition.prototype._stop = function stop() {
|
|
|
175
176
|
broker.cancel(`_api-delegated-${this.executionId}`);
|
|
176
177
|
};
|
|
177
178
|
|
|
179
|
+
TimerEventDefinition.prototype.parse = function parse(timerType, value) {
|
|
180
|
+
let repeat, delay, expireAt;
|
|
181
|
+
switch (timerType) {
|
|
182
|
+
case 'timeCycle':
|
|
183
|
+
case 'timeDuration': {
|
|
184
|
+
const parsed = parseIsoDuration(value);
|
|
185
|
+
if (parsed.repeat) repeat = parsed.repeat;
|
|
186
|
+
delay = toSeconds(parsed) * 1000;
|
|
187
|
+
expireAt = new Date(Date.now() + delay);
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
case 'timeDate': {
|
|
191
|
+
const ms = Date.parse(value);
|
|
192
|
+
if (!isNaN(ms)) {
|
|
193
|
+
expireAt = new Date(ms);
|
|
194
|
+
delay = Date.now() - expireAt;
|
|
195
|
+
} else {
|
|
196
|
+
throw new TypeError(`invalid timeDate >${value}<`);
|
|
197
|
+
}
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
expireAt,
|
|
204
|
+
repeat,
|
|
205
|
+
delay,
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
|
|
178
209
|
TimerEventDefinition.prototype._getTimers = function getTimers(executeMessage) {
|
|
179
210
|
const content = executeMessage.content;
|
|
180
211
|
|
|
181
|
-
const now = Date.now();
|
|
182
212
|
const result = {
|
|
183
213
|
...('expireAt' in content && {expireAt: new Date(content.expireAt)}),
|
|
184
214
|
};
|
|
185
215
|
|
|
216
|
+
let parseErr;
|
|
186
217
|
for (const t of ['timeDuration', 'timeDate', 'timeCycle']) {
|
|
187
218
|
if (t in content) result[t] = content[t];
|
|
188
219
|
else if (t in this) result[t] = this.environment.resolveExpression(this[t], executeMessage);
|
|
@@ -191,47 +222,37 @@ TimerEventDefinition.prototype._getTimers = function getTimers(executeMessage) {
|
|
|
191
222
|
let expireAtDate, repeat;
|
|
192
223
|
const timerStr = result[t];
|
|
193
224
|
if (timerStr) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const delay = this._getDurationInMilliseconds(timerStr);
|
|
201
|
-
if (delay !== undefined) expireAtDate = new Date(now + delay);
|
|
202
|
-
break;
|
|
203
|
-
}
|
|
204
|
-
case 'timeDate': {
|
|
205
|
-
const dateStr = result[t];
|
|
206
|
-
const ms = Date.parse(dateStr);
|
|
207
|
-
if (!isNaN(ms)) {
|
|
208
|
-
expireAtDate = new Date(ms);
|
|
209
|
-
} else {
|
|
210
|
-
this._warn(`invalid timeDate >${dateStr}<`);
|
|
211
|
-
}
|
|
212
|
-
break;
|
|
213
|
-
}
|
|
225
|
+
try {
|
|
226
|
+
const {repeat: parsedRepeat, expireAt: parsedExpireAt} = this.parse(t, timerStr);
|
|
227
|
+
repeat = parsedRepeat;
|
|
228
|
+
expireAtDate = parsedExpireAt;
|
|
229
|
+
} catch (err) {
|
|
230
|
+
parseErr = err;
|
|
214
231
|
}
|
|
215
232
|
} else {
|
|
216
|
-
expireAtDate = new Date(
|
|
233
|
+
expireAtDate = new Date();
|
|
217
234
|
}
|
|
218
235
|
|
|
219
236
|
if (!expireAtDate) continue;
|
|
220
237
|
if (!('expireAt' in result) || result.expireAt > expireAtDate) {
|
|
221
238
|
result.timerType = t;
|
|
222
239
|
result.expireAt = expireAtDate;
|
|
223
|
-
|
|
240
|
+
result.repeat = repeat;
|
|
224
241
|
}
|
|
225
242
|
}
|
|
226
243
|
|
|
227
244
|
if ('expireAt' in result) {
|
|
228
|
-
result.timeout = result.expireAt - now;
|
|
245
|
+
result.timeout = result.expireAt - Date.now();
|
|
229
246
|
} else if ('timeout' in content) {
|
|
230
247
|
result.timeout = content.timeout;
|
|
231
248
|
} else if (!Object.keys(result).length) {
|
|
232
249
|
result.timeout = 0;
|
|
233
250
|
}
|
|
234
251
|
|
|
252
|
+
if (!('timeout' in result) && parseErr) {
|
|
253
|
+
this.logger.warn(`<${this.activity.id}> failed to parse timer: ${parseErr.message}`);
|
|
254
|
+
}
|
|
255
|
+
|
|
235
256
|
if (content.inbound && 'repeat' in content.inbound[0]) {
|
|
236
257
|
result.repeat = content.inbound[0].repeat;
|
|
237
258
|
}
|
|
@@ -239,18 +260,6 @@ TimerEventDefinition.prototype._getTimers = function getTimers(executeMessage) {
|
|
|
239
260
|
return result;
|
|
240
261
|
};
|
|
241
262
|
|
|
242
|
-
TimerEventDefinition.prototype._getDurationInMilliseconds = function getDurationInMilliseconds(duration) {
|
|
243
|
-
try {
|
|
244
|
-
return toSeconds(parse(duration)) * 1000;
|
|
245
|
-
} catch (err) {
|
|
246
|
-
this._warn(`failed to parse ${this.timerType} >${duration}<: ${err.message}`);
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
|
|
250
263
|
TimerEventDefinition.prototype._debug = function debug(msg) {
|
|
251
264
|
this.logger.debug(`<${this.executionId} (${this.activity.id})> ${msg}`);
|
|
252
265
|
};
|
|
253
|
-
|
|
254
|
-
TimerEventDefinition.prototype._warn = function debug(msg) {
|
|
255
|
-
this.logger.warn(`<${this.executionId} (${this.activity.id})> ${msg}`);
|
|
256
|
-
};
|
package/src/index.js
CHANGED
|
@@ -23,6 +23,7 @@ import InclusiveGateway from './gateways/InclusiveGateway.js';
|
|
|
23
23
|
import InputOutputSpecification from './io/InputOutputSpecification.js';
|
|
24
24
|
import IntermediateCatchEvent from './events/IntermediateCatchEvent.js';
|
|
25
25
|
import IntermediateThrowEvent from './events/IntermediateThrowEvent.js';
|
|
26
|
+
import Lane from './process/Lane.js';
|
|
26
27
|
import LinkEventDefinition from './eventDefinitions/LinkEventDefinition.js';
|
|
27
28
|
import LoopCharacteristics from './tasks/LoopCharacteristics.js';
|
|
28
29
|
import Message from './activity/Message.js';
|
|
@@ -46,6 +47,8 @@ import Task from './tasks/Task.js';
|
|
|
46
47
|
import TerminateEventDefinition from './eventDefinitions/TerminateEventDefinition.js';
|
|
47
48
|
import TimerEventDefinition from './eventDefinitions/TimerEventDefinition.js';
|
|
48
49
|
import Transaction from './tasks/Transaction.js';
|
|
50
|
+
import {Timers} from './Timers.js';
|
|
51
|
+
import * as ISODuration from './iso-duration.js';
|
|
49
52
|
|
|
50
53
|
export {
|
|
51
54
|
Association,
|
|
@@ -80,6 +83,7 @@ export {
|
|
|
80
83
|
Message,
|
|
81
84
|
MessageEventDefinition,
|
|
82
85
|
MessageFlow,
|
|
86
|
+
Lane,
|
|
83
87
|
LoopCharacteristics as MultiInstanceLoopCharacteristics,
|
|
84
88
|
ParallelGateway,
|
|
85
89
|
Process,
|
|
@@ -103,4 +107,6 @@ export {
|
|
|
103
107
|
TerminateEventDefinition,
|
|
104
108
|
TimerEventDefinition,
|
|
105
109
|
Transaction,
|
|
110
|
+
Timers,
|
|
111
|
+
ISODuration,
|
|
106
112
|
};
|