@ejfdelgado/ejflab-common 1.7.4 → 1.8.1
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/package.json
CHANGED
|
@@ -392,7 +392,7 @@ class FlowChartExec {
|
|
|
392
392
|
let instance = this.createInstance(commandName, id, txt, args);
|
|
393
393
|
index++;
|
|
394
394
|
const response1 = `${commandName}${JSON.stringify(args)}`;
|
|
395
|
-
const { canContinue, abort } = await instance.executeAsNode(args);
|
|
395
|
+
const { canContinue, abort } = await instance.executeAsNode(args, argsTxt);
|
|
396
396
|
if (abort) {
|
|
397
397
|
// Panic and halt all
|
|
398
398
|
this.mustEnd = true;
|
|
@@ -429,7 +429,7 @@ class FlowChartExec {
|
|
|
429
429
|
}
|
|
430
430
|
index++;
|
|
431
431
|
const response1 = `${commandName}${JSON.stringify(args)}`;
|
|
432
|
-
const { canContinue, abort } = await instance.executeAsArrow(args);
|
|
432
|
+
const { canContinue, abort } = await instance.executeAsArrow(args, argsTxt);
|
|
433
433
|
if (abort) {
|
|
434
434
|
// Panic and halt all
|
|
435
435
|
this.mustEnd = true;
|
|
@@ -15,7 +15,11 @@ class StepBasic {
|
|
|
15
15
|
nextTry = null;
|
|
16
16
|
commandName;
|
|
17
17
|
argsTxt;
|
|
18
|
+
argsTxtIndividual;
|
|
18
19
|
fireTime;
|
|
20
|
+
startTime = null;
|
|
21
|
+
endTime = null;
|
|
22
|
+
duration = null;
|
|
19
23
|
constructor(context, id, commandName, argsTxt) {
|
|
20
24
|
this.context = context;
|
|
21
25
|
this.id = id;
|
|
@@ -28,7 +32,42 @@ class StepBasic {
|
|
|
28
32
|
setMaxTries(value) {
|
|
29
33
|
this.maxErrorCount = value;
|
|
30
34
|
}
|
|
31
|
-
|
|
35
|
+
tic() {
|
|
36
|
+
this.startTime = new Date().getTime();
|
|
37
|
+
}
|
|
38
|
+
toc() {
|
|
39
|
+
let MAX_TIME_DATA = 10;
|
|
40
|
+
this.endTime = new Date().getTime();
|
|
41
|
+
this.duration = this.endTime - this.startTime;
|
|
42
|
+
// Read the performance object
|
|
43
|
+
let performance = SimpleObj.getValue(this.context.data, "performance", {});
|
|
44
|
+
if (performance.track !== true) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (typeof performance.n == "number") {
|
|
48
|
+
MAX_TIME_DATA = performance.n;
|
|
49
|
+
}
|
|
50
|
+
// Notify
|
|
51
|
+
const idTxt = `${this.commandName}«${this.argsTxtIndividual}»`;
|
|
52
|
+
const id = "d" + Buffer.from(idTxt).toString('base64');
|
|
53
|
+
if (!(id in performance)) {
|
|
54
|
+
const val = {
|
|
55
|
+
txt: idTxt,
|
|
56
|
+
time: [this.duration],
|
|
57
|
+
}
|
|
58
|
+
SimpleObj.recreate(this.context.data, `performance.${id}`, val);
|
|
59
|
+
} else {
|
|
60
|
+
const val = performance[id];
|
|
61
|
+
val.time.push(this.duration);
|
|
62
|
+
const overflow = val.time.length - MAX_TIME_DATA;
|
|
63
|
+
if (overflow > 0) {
|
|
64
|
+
val.time.splice(0, overflow);
|
|
65
|
+
}
|
|
66
|
+
SimpleObj.recreate(this.context.data, `performance.${id}.time`, val.time);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async executeAsNode(args, argsTxtIndividual) {
|
|
70
|
+
this.argsTxtIndividual = argsTxtIndividual;
|
|
32
71
|
const answer = {
|
|
33
72
|
canContinue: false,
|
|
34
73
|
abort: false,
|
|
@@ -48,8 +87,10 @@ class StepBasic {
|
|
|
48
87
|
}
|
|
49
88
|
try {
|
|
50
89
|
this.args = args;
|
|
90
|
+
this.tic();
|
|
51
91
|
await this.execFirst();
|
|
52
92
|
await this.execLast({ isCommand: true });
|
|
93
|
+
this.toc();
|
|
53
94
|
answer.canContinue = true;
|
|
54
95
|
this.resetErrorState();
|
|
55
96
|
return answer;
|
|
@@ -59,7 +100,8 @@ class StepBasic {
|
|
|
59
100
|
return answer;
|
|
60
101
|
}
|
|
61
102
|
}
|
|
62
|
-
async executeAsArrow(args) {
|
|
103
|
+
async executeAsArrow(args, argsTxtIndividual) {
|
|
104
|
+
this.argsTxtIndividual = argsTxtIndividual;
|
|
63
105
|
const answer = {
|
|
64
106
|
canContinue: false,
|
|
65
107
|
abort: false,
|
|
@@ -86,6 +128,7 @@ class StepBasic {
|
|
|
86
128
|
}
|
|
87
129
|
}
|
|
88
130
|
if (this.firstTime) {
|
|
131
|
+
this.tic();
|
|
89
132
|
const done = await this.execFirst();
|
|
90
133
|
if (done === false) {
|
|
91
134
|
return answer;
|
|
@@ -96,6 +139,7 @@ class StepBasic {
|
|
|
96
139
|
answer.canContinue = await this.canContinue();
|
|
97
140
|
if (answer.canContinue) {
|
|
98
141
|
await this.execLast();
|
|
142
|
+
this.toc();
|
|
99
143
|
this.fired = true;
|
|
100
144
|
this.resetErrorState();
|
|
101
145
|
} else {
|
|
@@ -2,18 +2,25 @@ const { StepBasic } = require("./StepBasic");
|
|
|
2
2
|
|
|
3
3
|
class StepSleep extends StepBasic {
|
|
4
4
|
startTime = null;
|
|
5
|
+
duration = null;
|
|
5
6
|
constructor(context, id, commandName, argsTxt) {
|
|
6
7
|
super(context, id, commandName, argsTxt);
|
|
7
8
|
super.alwaysEvaluateCanContinue = false;
|
|
8
9
|
}
|
|
9
10
|
async execFirst() {
|
|
10
11
|
this.startTime = new Date().getTime();
|
|
12
|
+
const minTime = this.args[0];
|
|
13
|
+
const maxTime = this.args[1];
|
|
14
|
+
if (typeof maxTime == "number") {
|
|
15
|
+
this.duration = minTime + Math.floor(Math.random() * (maxTime - minTime));
|
|
16
|
+
} else {
|
|
17
|
+
this.duration = minTime;
|
|
18
|
+
}
|
|
11
19
|
}
|
|
12
20
|
|
|
13
21
|
async canContinue() {
|
|
14
|
-
const minTime = this.args[0];
|
|
15
22
|
const diff = new Date().getTime() - this.startTime;
|
|
16
|
-
return diff >=
|
|
23
|
+
return diff >= this.duration;
|
|
17
24
|
}
|
|
18
25
|
}
|
|
19
26
|
|