node-automator 1.4.9 → 1.4.10
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/index.js +19 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -70,11 +70,18 @@ async function getCfgs() {
|
|
|
70
70
|
async function MainProcess() {
|
|
71
71
|
const enableTimer = argv.ENABLE_TIMER;
|
|
72
72
|
const timerInterval = argv.TIMER_INTERVAL;
|
|
73
|
+
const estimateTime = +argv.ESTIMATE_TIME;
|
|
73
74
|
let beginTime = Date.now();
|
|
74
75
|
let timer;
|
|
75
76
|
if (enableTimer && timerInterval) {
|
|
76
77
|
timer = setInterval(() => {
|
|
77
|
-
|
|
78
|
+
const elapsedTime = Date.now() - beginTime;
|
|
79
|
+
if (!estimateTime) {
|
|
80
|
+
info(`\r[${formatTimestampMillisec(Date.now())}] 任务已运行 ${formatTimeInMillisec(elapsedTime, "hh:mm:ss")} ${clear_line_end}`, "");
|
|
81
|
+
} else {
|
|
82
|
+
const estimateLeft = Math.max(0, estimateTime - elapsedTime);
|
|
83
|
+
info(`\r[${formatTimestampMillisec(Date.now())}] 任务已运行 ${formatTimeInMillisec(elapsedTime, "hh:mm:ss")}, 预计剩余 ${formatTimeInMillisec(estimateLeft, "hh:mm:ss")} ${clear_line_end}`, "");
|
|
84
|
+
}
|
|
78
85
|
}, timerInterval);
|
|
79
86
|
}
|
|
80
87
|
let lastError = null;
|
|
@@ -98,7 +105,17 @@ async function MainProcess() {
|
|
|
98
105
|
if (enableTimer) {
|
|
99
106
|
clearInterval(timer);
|
|
100
107
|
info("")
|
|
101
|
-
|
|
108
|
+
const costTime = Date.now() - beginTime;
|
|
109
|
+
let timeLog = `任务总耗时 ${formatTimeInMillisec(costTime, "hh:mm:ss")}`;
|
|
110
|
+
if (estimateTime) {
|
|
111
|
+
const offsetTime = costTime - estimateTime;
|
|
112
|
+
if (offsetTime > 0) {
|
|
113
|
+
timeLog += `, 比预期慢了 ${formatTimeInMillisec(offsetTime, "hh:mm:ss")}`;
|
|
114
|
+
} else {
|
|
115
|
+
timeLog += `, 比预期快了 ${formatTimeInMillisec(-offsetTime, "hh:mm:ss")}`;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
success(`>>> ${timeLog} <<<`, undefined, undefined, true);
|
|
102
119
|
}
|
|
103
120
|
|
|
104
121
|
let code = lastError ? (getLastErrorCode() || 1) : 0;
|