node-automator 1.4.23 → 1.4.25

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 CHANGED
@@ -11,10 +11,10 @@ require('dotenv').config({
11
11
 
12
12
  // 禁用其他打印
13
13
  console.yzplog = console.log;
14
- console.log = () => {};
15
- console.warn = () => {};
16
- console.info = () => {};
17
- console.error = () => {};
14
+ console.log = () => { };
15
+ console.warn = () => { };
16
+ console.info = () => { };
17
+ console.error = () => { };
18
18
 
19
19
  const mgr = require("./commands/mgr");
20
20
  const {
@@ -42,6 +42,8 @@ const {
42
42
  } = require("./commands/share_data");
43
43
  const { decode } = require('./utils/base64_tool');
44
44
  const { formatTimeInMillisec, formatTimestampMillisec } = require('./utils/transform_tool');
45
+ const { hash } = require('./utils/hash_tool');
46
+ const { getCache, setCache } = require('./utils/cache_tool');
45
47
 
46
48
  process.on('exit', (code) => {
47
49
  if (!code) {
@@ -67,9 +69,13 @@ async function getCfgs() {
67
69
  });
68
70
  }
69
71
  async function MainProcess() {
72
+ let lastError = null;
73
+ const cfgs = await getCfgs();
74
+ const cfgHash = hash(cfgs).toString();
70
75
  const enableTimer = argv.ENABLE_TIMER;
71
- const timerInterval = argv.TIMER_INTERVAL;
72
- const estimateTime = +argv.ESTIMATE_TIME;
76
+ const timerInterval = argv.TIMER_INTERVAL || 1000;
77
+ const CACHE_KEY_ESTIMATE_TIME = `ESTIMATE_TIME_${cfgHash}`;
78
+ const estimateTime = +argv.ESTIMATE_TIME || +(await getCache(CACHE_KEY_ESTIMATE_TIME)) || 0;
73
79
  let beginTime = Date.now();
74
80
  let timer;
75
81
  if (enableTimer && timerInterval) {
@@ -83,8 +89,6 @@ async function MainProcess() {
83
89
  }
84
90
  }, timerInterval);
85
91
  }
86
- let lastError = null;
87
- const cfgs = await getCfgs();
88
92
  try {
89
93
  if (cfgs.indexOf(".") != -1) {
90
94
  await mgr.exec([{
@@ -101,21 +105,22 @@ async function MainProcess() {
101
105
  } catch (err) {
102
106
  lastError = err.message || err;
103
107
  }
108
+ const costTime = Date.now() - beginTime;
104
109
  if (enableTimer) {
105
110
  clearInterval(timer);
106
111
  info("")
107
- const costTime = Date.now() - beginTime;
108
112
  let timeLog = `任务总耗时 ${formatTimeInMillisec(costTime, "hh:mm:ss")}`;
109
113
  if (estimateTime) {
110
114
  const offsetTime = costTime - estimateTime;
111
115
  if (offsetTime > 0) {
112
- timeLog += `, 比预期慢了 ${formatTimeInMillisec(offsetTime, "hh:mm:ss")}`;
116
+ timeLog += `, 比预期慢了 ${formatTimeInMillisec(offsetTime, "hh:mm:ss SSS")}`;
113
117
  } else {
114
- timeLog += `, 比预期快了 ${formatTimeInMillisec(-offsetTime, "hh:mm:ss")}`;
118
+ timeLog += `, 比预期快了 ${formatTimeInMillisec(-offsetTime, "hh:mm:ss SSS")}`;
115
119
  }
116
120
  }
117
121
  success(`>>> ${timeLog} <<<`, undefined, undefined, true);
118
122
  }
123
+ await setCache(CACHE_KEY_ESTIMATE_TIME, costTime);
119
124
 
120
125
  let code = lastError ? (getLastErrorCode() || 1) : 0;
121
126
  let extname = path.extname(argv.$0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-automator",
3
- "version": "1.4.23",
3
+ "version": "1.4.25",
4
4
  "description": "Execute automation with yaml configuration(compatible with json)",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -37,7 +37,7 @@ async function doRequest(data) {
37
37
  let result;
38
38
  let useCache = enable_http_cache && http_cache;
39
39
  let quiet = data.quiet;
40
- !quiet && info(useCache ? "[缓存]" : `[${options.method}] ${url} `);
40
+ !quiet && info(`[${options.method}] ${url}` + (useCache ? "[缓存]" : ""));
41
41
  let hasProgress = false;
42
42
  let fileDst = get_full_path(data.dst || shareData.AUTOMATOR_SCRATCH + "/request_tool/" + cache_name, "FILE");
43
43
  if (useCache) {