@abtnode/util 1.16.51 → 1.16.52-beta-20250909-073849-4e392ab1

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,6 +4,7 @@
4
4
  const fs = require('node:fs');
5
5
  const path = require('node:path');
6
6
  const os = require('node:os');
7
+ const debug = require('debug')('@core/util:pm2-start-or-reload');
7
8
  const pm2 = require('./async-pm2');
8
9
 
9
10
  function getTempEnvPath(name) {
@@ -97,14 +98,47 @@ async function isProcessRunningByPm2(name) {
97
98
  return isHasRunning;
98
99
  }
99
100
 
101
+ async function getCurrentProcessCount(name) {
102
+ const count = await new Promise((resolve) => {
103
+ pm2.list((err, list) => {
104
+ if (err) {
105
+ return resolve(0);
106
+ }
107
+
108
+ const procs = list.filter((p) => p.name === name);
109
+ resolve(procs.length);
110
+ });
111
+ });
112
+
113
+ return count;
114
+ }
115
+
100
116
  async function pm2StartOrReload(config = {}) {
101
- const { name } = config;
117
+ const { name, instances, execMode } = config;
102
118
  const tempEnvPath = getTempEnvPath(name);
103
119
  fs.writeFileSync(tempEnvPath, JSON.stringify(config.env));
104
120
 
105
121
  const isHasRunning = await isProcessRunningByPm2(name);
106
122
 
107
123
  if (isHasRunning) {
124
+ // Check if we need to restart for cluster mode with different instance count
125
+ debug('execMode', execMode, instances);
126
+ if (execMode === 'cluster' && instances) {
127
+ const currentCount = await getCurrentProcessCount(name);
128
+ debug('current instance count', currentCount);
129
+
130
+ if (currentCount !== instances) {
131
+ try {
132
+ await pm2.deleteAsync(name);
133
+ debug('existing processes deleted', name);
134
+ } catch (error) {
135
+ debug('delete existing processes error', error);
136
+ }
137
+ await pm2.startAsync(config);
138
+ return;
139
+ }
140
+ }
141
+
108
142
  await pm2ReloadWithEnv(config);
109
143
  } else {
110
144
  await pm2.startAsync(config);
@@ -114,5 +148,6 @@ async function pm2StartOrReload(config = {}) {
114
148
  module.exports = {
115
149
  loadReloadEnv,
116
150
  isProcessRunningByPm2,
151
+ getCurrentProcessCount,
117
152
  pm2StartOrReload,
118
153
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.51",
6
+ "version": "1.16.52-beta-20250909-073849-4e392ab1",
7
7
  "description": "ArcBlock's JavaScript utility",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,15 +18,15 @@
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.51",
22
- "@abtnode/db-cache": "1.16.51",
21
+ "@abtnode/constant": "1.16.52-beta-20250909-073849-4e392ab1",
22
+ "@abtnode/db-cache": "1.16.52-beta-20250909-073849-4e392ab1",
23
23
  "@arcblock/did": "1.24.0",
24
24
  "@arcblock/event-hub": "1.24.0",
25
25
  "@arcblock/pm2": "^6.0.12",
26
- "@blocklet/constant": "1.16.51",
26
+ "@blocklet/constant": "1.16.52-beta-20250909-073849-4e392ab1",
27
27
  "@blocklet/error": "^0.2.5",
28
- "@blocklet/meta": "1.16.51",
29
- "@blocklet/xss": "^0.2.6",
28
+ "@blocklet/meta": "1.16.52-beta-20250909-073849-4e392ab1",
29
+ "@blocklet/xss": "^0.2.7",
30
30
  "@ocap/client": "1.24.0",
31
31
  "@ocap/mcrypto": "1.24.0",
32
32
  "@ocap/util": "1.24.0",
@@ -91,5 +91,5 @@
91
91
  "fs-extra": "^11.2.0",
92
92
  "jest": "^29.7.0"
93
93
  },
94
- "gitHead": "32897dd6a5e92368f1870bba34cbbb38da95da89"
94
+ "gitHead": "3b4b1551b181606f84799ba8b294fb36b483c9c3"
95
95
  }