refactor(metrics): 调整 MetricsHttpServer 注册关闭钩子的时机.

将关闭钩子的时机调整到 main 方法中, 可以减少多余的钩子注册(比如测试时无需注册钩子, 却还是注册了).
This commit is contained in:
LamGC 2022-06-29 03:06:15 +08:00
parent 1afe0f07a8
commit ae411ce829
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D

View File

@ -33,7 +33,7 @@ fun main(args: Array<String>): Unit = runBlocking {
val launcher = Launcher() val launcher = Launcher()
.registerShutdownHook() .registerShutdownHook()
startMetricsServer() startMetricsServer()?.registerShutdownHook()
if (!launcher.launch()) { if (!launcher.launch()) {
exitProcess(1) exitProcess(1)
} }
@ -57,7 +57,6 @@ internal fun startMetricsServer(config: MetricsConfig = Const.config.metrics): H
val httpServer = builder val httpServer = builder
.build() .build()
.registerShutdownHook()
log.info { "运行指标服务器已启动. (Port: ${httpServer.port})" } log.info { "运行指标服务器已启动. (Port: ${httpServer.port})" }
return httpServer return httpServer
} }