@abtnode/util 1.16.49-beta-20250823-082650-626c1473 → 1.16.49-beta-20250827-025603-2bb1a7ee

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.
@@ -4,20 +4,42 @@ const pm2 = require('./pm2/async-pm2');
4
4
 
5
5
  const noop = () => {};
6
6
 
7
- const getPm2ProcessInfo = (processId, { printError = noop, throwOnNotExist = true } = {}) =>
8
- new Promise((resolve, reject) => {
9
- pm2.describe(processId, (err, [info]) => {
7
+ // 新增 10_000 ms 的超时时间,避免 pm2 遇到什么问题一直不返回
8
+ const getPm2ProcessInfo = (processId, { printError = noop, throwOnNotExist = true, timeout = 10_000 } = {}) => {
9
+ return new Promise((resolve, reject) => {
10
+ let settled = false;
11
+
12
+ let timer;
13
+ const onSettle = (fn, arg) => {
14
+ if (settled) return;
15
+ settled = true;
16
+ clearTimeout(timer);
17
+ fn(arg);
18
+ };
19
+
20
+ timer = setTimeout(() => {
21
+ printError('pm2.describe timeout', { processId, timeout });
22
+ onSettle(reject, new CustomError('PM2_RPC_TIMEOUT', `pm2.describe(${processId}) timed out after ${timeout}ms`));
23
+ }, timeout);
24
+
25
+ pm2.describe(processId, (err, list) => {
10
26
  if (err) {
11
27
  printError('Failed to get blocklet status from pm2', { error: err });
12
- return reject(err);
28
+ return onSettle(reject, err);
13
29
  }
14
30
 
31
+ const info = Array.isArray(list) ? list[0] : undefined;
32
+
15
33
  if (!info && throwOnNotExist) {
16
- return reject(new CustomError('BLOCKLET_PROCESS_404', `Blocklet process info is not available: ${processId}`));
34
+ return onSettle(
35
+ reject,
36
+ new CustomError('BLOCKLET_PROCESS_404', `Blocklet process info is not available: ${processId}`)
37
+ );
17
38
  }
18
39
 
19
- return resolve(info);
40
+ return onSettle(resolve, info || null);
20
41
  });
21
42
  });
43
+ };
22
44
 
23
45
  module.exports = getPm2ProcessInfo;
@@ -53,23 +53,6 @@ function waitProcOnlineById(id, timeout = 20_000) {
53
53
  });
54
54
  }
55
55
 
56
- /** 等待该 app 的 cluster 全 online */
57
- function waitSomeInstancesOnline(name, instances, timeoutMs = 20_000) {
58
- const start = Date.now();
59
- return new Promise((resolve, reject) => {
60
- (function poll() {
61
- pm2.list((err, list) => {
62
- if (err) return reject(err);
63
- const procs = list.filter((p) => p.name === name);
64
- const online = procs.filter((p) => p.pm2_env?.status === 'online').length;
65
- if (online >= instances) return resolve();
66
- if (Date.now() - start > timeoutMs) return reject(new Error('instances not online in time'));
67
- setTimeout(poll, 120);
68
- });
69
- })();
70
- });
71
- }
72
-
73
56
  async function rollingRestartWithEnv(config) {
74
57
  // eslint-disable-next-line camelcase
75
58
  const { name, listen_timeout = 20_000 } = config;
@@ -126,12 +109,10 @@ async function pm2StartOrReload(config = {}) {
126
109
  } else {
127
110
  await pm2.startAsync(config);
128
111
  }
129
- await waitSomeInstancesOnline(name, config.instances);
130
112
  }
131
113
 
132
114
  module.exports = {
133
115
  loadReloadEnv,
134
116
  isProcessRunningByPm2,
135
- waitSomeInstancesOnline,
136
117
  pm2StartOrReload,
137
118
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.49-beta-20250823-082650-626c1473",
6
+ "version": "1.16.49-beta-20250827-025603-2bb1a7ee",
7
7
  "description": "ArcBlock's JavaScript utility",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,14 +18,14 @@
18
18
  "author": "polunzh <polunzh@gmail.com> (http://github.com/polunzh)",
19
19
  "license": "Apache-2.0",
20
20
  "dependencies": {
21
- "@abtnode/constant": "1.16.49-beta-20250823-082650-626c1473",
22
- "@abtnode/db-cache": "1.16.49-beta-20250823-082650-626c1473",
21
+ "@abtnode/constant": "1.16.49-beta-20250827-025603-2bb1a7ee",
22
+ "@abtnode/db-cache": "1.16.49-beta-20250827-025603-2bb1a7ee",
23
23
  "@arcblock/did": "1.22.2",
24
24
  "@arcblock/event-hub": "1.22.2",
25
25
  "@arcblock/pm2": "^6.0.12",
26
- "@blocklet/constant": "1.16.49-beta-20250823-082650-626c1473",
26
+ "@blocklet/constant": "1.16.49-beta-20250827-025603-2bb1a7ee",
27
27
  "@blocklet/error": "^0.2.5",
28
- "@blocklet/meta": "1.16.49-beta-20250823-082650-626c1473",
28
+ "@blocklet/meta": "1.16.49-beta-20250827-025603-2bb1a7ee",
29
29
  "@blocklet/xss": "^0.2.5",
30
30
  "@ocap/client": "1.22.2",
31
31
  "@ocap/mcrypto": "1.22.2",
@@ -91,5 +91,5 @@
91
91
  "fs-extra": "^11.2.0",
92
92
  "jest": "^29.7.0"
93
93
  },
94
- "gitHead": "54d2281fc6f72dadd12ed86b38d5a4e150bcaba8"
94
+ "gitHead": "2b70eea34e8bc8546abb09d38935e8906d9586fd"
95
95
  }