node-automator 1.4.8 → 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 +35 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -38,9 +38,11 @@ const {
|
|
|
38
38
|
parse
|
|
39
39
|
} = require("./utils/parse_tool");
|
|
40
40
|
const {
|
|
41
|
-
shareData
|
|
41
|
+
shareData,
|
|
42
|
+
clear_line_end
|
|
42
43
|
} = require("./commands/share_data");
|
|
43
44
|
const { decode } = require('./utils/base64_tool');
|
|
45
|
+
const { formatTimeInMillisec, formatTimestampMillisec } = require('./utils/transform_tool');
|
|
44
46
|
|
|
45
47
|
process.on('exit', (code) => {
|
|
46
48
|
if (!code) {
|
|
@@ -66,6 +68,22 @@ async function getCfgs() {
|
|
|
66
68
|
});
|
|
67
69
|
}
|
|
68
70
|
async function MainProcess() {
|
|
71
|
+
const enableTimer = argv.ENABLE_TIMER;
|
|
72
|
+
const timerInterval = argv.TIMER_INTERVAL;
|
|
73
|
+
const estimateTime = +argv.ESTIMATE_TIME;
|
|
74
|
+
let beginTime = Date.now();
|
|
75
|
+
let timer;
|
|
76
|
+
if (enableTimer && timerInterval) {
|
|
77
|
+
timer = setInterval(() => {
|
|
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
|
+
}
|
|
85
|
+
}, timerInterval);
|
|
86
|
+
}
|
|
69
87
|
let lastError = null;
|
|
70
88
|
const cfgs = await getCfgs();
|
|
71
89
|
try {
|
|
@@ -84,6 +102,22 @@ async function MainProcess() {
|
|
|
84
102
|
} catch (err) {
|
|
85
103
|
lastError = err.message || err;
|
|
86
104
|
}
|
|
105
|
+
if (enableTimer) {
|
|
106
|
+
clearInterval(timer);
|
|
107
|
+
info("")
|
|
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);
|
|
119
|
+
}
|
|
120
|
+
|
|
87
121
|
let code = lastError ? (getLastErrorCode() || 1) : 0;
|
|
88
122
|
let extname = path.extname(argv.$0);
|
|
89
123
|
let hasError = code != 0;
|