@abtnode/util 1.16.43-beta-20250429-130236-269254ff → 1.16.43-beta-20250430-225854-7914dfe4
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/lib/ensure-endpoint-healthy.js +25 -4
- package/package.json +10 -10
|
@@ -5,6 +5,7 @@ const sleep = require('./sleep');
|
|
|
5
5
|
const tryWithTimeout = require('./try-with-timeout');
|
|
6
6
|
|
|
7
7
|
const ONE_SECOND = 1000;
|
|
8
|
+
const WAIT_TCP_TIME = 3000;
|
|
8
9
|
|
|
9
10
|
const dial = (host, port) =>
|
|
10
11
|
new Promise((resolve, reject) => {
|
|
@@ -88,6 +89,7 @@ const ensureStarted = async ({
|
|
|
88
89
|
timeout = 10 * ONE_SECOND,
|
|
89
90
|
elapse = 0,
|
|
90
91
|
minConsecutiveTime = 3 * ONE_SECOND,
|
|
92
|
+
waitTCP = false,
|
|
91
93
|
}) => {
|
|
92
94
|
const startTime = Date.now();
|
|
93
95
|
try {
|
|
@@ -95,6 +97,10 @@ const ensureStarted = async ({
|
|
|
95
97
|
await dialHttp(host, port, minConsecutiveTime);
|
|
96
98
|
} else {
|
|
97
99
|
await dial(host, port);
|
|
100
|
+
// 如果是 TCP 协议, 标注需要等待 TCP 的,则需要等待 3 秒,确保服务已经启动,例如 MySQL 这种
|
|
101
|
+
if (waitTCP) {
|
|
102
|
+
await sleep(WAIT_TCP_TIME);
|
|
103
|
+
}
|
|
98
104
|
}
|
|
99
105
|
debug('ping if started', { port });
|
|
100
106
|
return true;
|
|
@@ -108,7 +114,7 @@ const ensureStarted = async ({
|
|
|
108
114
|
throw new Error(`service not ready within ${Math.ceil(timeout / ONE_SECOND)} seconds, error: ${err?.message}`);
|
|
109
115
|
}
|
|
110
116
|
|
|
111
|
-
return ensureStarted({ host, port, protocol, timeout, elapse: spend });
|
|
117
|
+
return ensureStarted({ host, port, protocol, timeout, elapse: spend, waitTCP });
|
|
112
118
|
}
|
|
113
119
|
};
|
|
114
120
|
|
|
@@ -119,6 +125,7 @@ module.exports = async ({
|
|
|
119
125
|
timeout = 10 * ONE_SECOND,
|
|
120
126
|
minConsecutiveTime = (+process.env.ENDPOINT_CONSECUTIVE_TIME || 5) * ONE_SECOND,
|
|
121
127
|
doConsecutiveCheck = true,
|
|
128
|
+
waitTCP = false,
|
|
122
129
|
// eslint-disable-next-line require-await
|
|
123
130
|
}) => {
|
|
124
131
|
debug('ensure endpoint healthy', { host, port, protocol, timeout, minConsecutiveTime, doConsecutiveCheck });
|
|
@@ -128,11 +135,25 @@ module.exports = async ({
|
|
|
128
135
|
}
|
|
129
136
|
|
|
130
137
|
return tryWithTimeout(async () => {
|
|
131
|
-
await ensureStarted({ host, port, protocol, timeout: timeout - minConsecutiveTime, minConsecutiveTime });
|
|
138
|
+
await ensureStarted({ host, port, protocol, timeout: timeout - minConsecutiveTime, minConsecutiveTime, waitTCP });
|
|
132
139
|
if (doConsecutiveCheck) {
|
|
133
140
|
try {
|
|
134
|
-
await ensureStarted({
|
|
135
|
-
|
|
141
|
+
await ensureStarted({
|
|
142
|
+
host,
|
|
143
|
+
port,
|
|
144
|
+
protocol,
|
|
145
|
+
timeout: timeout - minConsecutiveTime,
|
|
146
|
+
minConsecutiveTime,
|
|
147
|
+
waitTCP,
|
|
148
|
+
});
|
|
149
|
+
await ensureStarted({
|
|
150
|
+
host,
|
|
151
|
+
port,
|
|
152
|
+
protocol,
|
|
153
|
+
timeout: timeout - minConsecutiveTime,
|
|
154
|
+
minConsecutiveTime,
|
|
155
|
+
waitTCP,
|
|
156
|
+
});
|
|
136
157
|
} catch (error) {
|
|
137
158
|
throw new Error(
|
|
138
159
|
`ensure healthy consecutive check failed in ${timeout - minConsecutiveTime}ms: ${error.message}`
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.43-beta-
|
|
6
|
+
"version": "1.16.43-beta-20250430-225854-7914dfe4",
|
|
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.43-beta-
|
|
22
|
-
"@arcblock/did": "
|
|
21
|
+
"@abtnode/constant": "1.16.43-beta-20250430-225854-7914dfe4",
|
|
22
|
+
"@arcblock/did": "1.20.4",
|
|
23
23
|
"@arcblock/pm2": "^5.4.0",
|
|
24
|
-
"@blocklet/constant": "1.16.43-beta-
|
|
25
|
-
"@blocklet/meta": "1.16.43-beta-
|
|
26
|
-
"@ocap/client": "1.20.
|
|
27
|
-
"@ocap/mcrypto": "1.20.
|
|
28
|
-
"@ocap/util": "1.20.
|
|
29
|
-
"@ocap/wallet": "1.20.
|
|
24
|
+
"@blocklet/constant": "1.16.43-beta-20250430-225854-7914dfe4",
|
|
25
|
+
"@blocklet/meta": "1.16.43-beta-20250430-225854-7914dfe4",
|
|
26
|
+
"@ocap/client": "1.20.4",
|
|
27
|
+
"@ocap/mcrypto": "1.20.4",
|
|
28
|
+
"@ocap/util": "1.20.4",
|
|
29
|
+
"@ocap/wallet": "1.20.4",
|
|
30
30
|
"archiver": "^7.0.1",
|
|
31
31
|
"axios": "^1.7.9",
|
|
32
32
|
"axios-mock-adapter": "^2.1.0",
|
|
@@ -86,5 +86,5 @@
|
|
|
86
86
|
"fs-extra": "^11.2.0",
|
|
87
87
|
"jest": "^29.7.0"
|
|
88
88
|
},
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "469f36a58a5906577fe86c5959887e3a0d6f9113"
|
|
90
90
|
}
|