node-automator 1.4.23 → 1.4.24

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,14 @@ 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;
79
+ console.yzplog(`estimateTime ${estimateTime}`)
73
80
  let beginTime = Date.now();
74
81
  let timer;
75
82
  if (enableTimer && timerInterval) {
@@ -83,8 +90,6 @@ async function MainProcess() {
83
90
  }
84
91
  }, timerInterval);
85
92
  }
86
- let lastError = null;
87
- const cfgs = await getCfgs();
88
93
  try {
89
94
  if (cfgs.indexOf(".") != -1) {
90
95
  await mgr.exec([{
@@ -101,21 +106,22 @@ async function MainProcess() {
101
106
  } catch (err) {
102
107
  lastError = err.message || err;
103
108
  }
109
+ const costTime = Date.now() - beginTime;
104
110
  if (enableTimer) {
105
111
  clearInterval(timer);
106
112
  info("")
107
- const costTime = Date.now() - beginTime;
108
113
  let timeLog = `任务总耗时 ${formatTimeInMillisec(costTime, "hh:mm:ss")}`;
109
114
  if (estimateTime) {
110
115
  const offsetTime = costTime - estimateTime;
111
116
  if (offsetTime > 0) {
112
- timeLog += `, 比预期慢了 ${formatTimeInMillisec(offsetTime, "hh:mm:ss")}`;
117
+ timeLog += `, 比预期慢了 ${formatTimeInMillisec(offsetTime, "hh:mm:ss SSS")}`;
113
118
  } else {
114
- timeLog += `, 比预期快了 ${formatTimeInMillisec(-offsetTime, "hh:mm:ss")}`;
119
+ timeLog += `, 比预期快了 ${formatTimeInMillisec(-offsetTime, "hh:mm:ss SSS")}`;
115
120
  }
116
121
  }
117
122
  success(`>>> ${timeLog} <<<`, undefined, undefined, true);
118
123
  }
124
+ await setCache(CACHE_KEY_ESTIMATE_TIME, costTime);
119
125
 
120
126
  let code = lastError ? (getLastErrorCode() || 1) : 0;
121
127
  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.24",
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) {