@hile/cli 2.0.8 → 2.0.10
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/dist/exitHook.d.ts +3 -2
- package/dist/exitHook.js +16 -26
- package/dist/index.js +11 -6
- package/package.json +4 -4
package/dist/exitHook.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* 注册进程退出钩子。
|
|
3
|
+
* 进程退出时先执行 container.shutdown(),完成后调用 exit() 调度 process.exit()。
|
|
4
|
+
* 若 process.exit() 被 pino/thread-stream 的 Atomics.wait() 阻塞,1s 后 process.abort() 兜底。
|
|
4
5
|
*/
|
|
5
6
|
export declare function registerExitHook(offEvent: () => void): void;
|
|
6
7
|
export declare function useExit(fn: () => void | Promise<void>): Promise<void>;
|
package/dist/exitHook.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import exitHook from 'async-exit-hook';
|
|
2
2
|
import { container } from '@hile/core';
|
|
3
|
-
/**
|
|
4
|
-
const FORCE_EXIT_AFTER_MS =
|
|
3
|
+
/** shutdown 未在该时间内完成时强制退出 */
|
|
4
|
+
const FORCE_EXIT_AFTER_MS = 10_000;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* 注册进程退出钩子。
|
|
7
|
+
* 进程退出时先执行 container.shutdown(),完成后调用 exit() 调度 process.exit()。
|
|
8
|
+
* 若 process.exit() 被 pino/thread-stream 的 Atomics.wait() 阻塞,1s 后 process.abort() 兜底。
|
|
8
9
|
*/
|
|
9
10
|
export function registerExitHook(offEvent) {
|
|
10
11
|
const hook = exitHook;
|
|
@@ -14,17 +15,9 @@ export function registerExitHook(offEvent) {
|
|
|
14
15
|
exitHook(async (exit) => {
|
|
15
16
|
try {
|
|
16
17
|
await container.shutdown();
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
process.stdin.unref();
|
|
21
|
-
}
|
|
22
|
-
resolve();
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
reject(e);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
18
|
+
if (process.stdin.isTTY) {
|
|
19
|
+
process.stdin.unref();
|
|
20
|
+
}
|
|
28
21
|
}
|
|
29
22
|
catch (e) {
|
|
30
23
|
console.error(e);
|
|
@@ -32,6 +25,10 @@ export function registerExitHook(offEvent) {
|
|
|
32
25
|
finally {
|
|
33
26
|
offEvent();
|
|
34
27
|
exit();
|
|
28
|
+
// process.exit() can hang due to pino/thread-stream exit handlers
|
|
29
|
+
// that use Atomics.wait() to block on worker threads.
|
|
30
|
+
// If we're still running after 1s, force kill.
|
|
31
|
+
setTimeout(() => process.abort(), 1000).unref();
|
|
35
32
|
}
|
|
36
33
|
});
|
|
37
34
|
}
|
|
@@ -39,23 +36,16 @@ export async function useExit(fn) {
|
|
|
39
36
|
exitHook(async (exit) => {
|
|
40
37
|
try {
|
|
41
38
|
await Promise.resolve(fn());
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
process.stdin.unref();
|
|
46
|
-
}
|
|
47
|
-
resolve();
|
|
48
|
-
}
|
|
49
|
-
catch (e) {
|
|
50
|
-
reject(e);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
39
|
+
if (process.stdin.isTTY) {
|
|
40
|
+
process.stdin.unref();
|
|
41
|
+
}
|
|
53
42
|
}
|
|
54
43
|
catch (e) {
|
|
55
44
|
console.error(e);
|
|
56
45
|
}
|
|
57
46
|
finally {
|
|
58
47
|
exit();
|
|
48
|
+
setTimeout(() => process.abort(), 1000).unref();
|
|
59
49
|
}
|
|
60
50
|
});
|
|
61
51
|
}
|
package/dist/index.js
CHANGED
|
@@ -120,15 +120,20 @@ registryCmd
|
|
|
120
120
|
.description('启动注册中心')
|
|
121
121
|
.action(async (options) => {
|
|
122
122
|
const port = options.port ? Number(options.port) : 9876;
|
|
123
|
+
const { logger, teardown } = createLogger({
|
|
124
|
+
level: options.level,
|
|
125
|
+
pretty: !!options.pretty
|
|
126
|
+
});
|
|
123
127
|
const registry = new Registry({
|
|
124
128
|
advertiseHost: options.host,
|
|
125
|
-
logger
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
+
logger,
|
|
130
|
+
});
|
|
131
|
+
const unListen = await registry.listen(port);
|
|
132
|
+
useExit(async () => {
|
|
133
|
+
await unListen();
|
|
134
|
+
teardown();
|
|
129
135
|
});
|
|
130
|
-
|
|
131
|
-
registry.logger.info(`+ registry started on port ${port}`);
|
|
136
|
+
logger.info(`+ registry started on port ${port}`);
|
|
132
137
|
});
|
|
133
138
|
// Registry configs subcommands
|
|
134
139
|
const configs = registryCmd.command('configs');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hile/cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@hile/core": "^2.0.1",
|
|
32
|
-
"@hile/logger": "^2.0.
|
|
33
|
-
"@hile/micro": "^2.0.
|
|
32
|
+
"@hile/logger": "^2.0.3",
|
|
33
|
+
"@hile/micro": "^2.0.7",
|
|
34
34
|
"async-exit-hook": "^2.0.1",
|
|
35
35
|
"commander": "^14.0.3",
|
|
36
36
|
"glob": "^13.0.6",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"tsx": "^4.21.0",
|
|
39
39
|
"yaml": "^2.9.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "cf057f1833ad144a6d7812d2d190d3a9d903429f"
|
|
42
42
|
}
|