refactor:简化main函数中pprof的关闭调用

This commit is contained in:
tangerineyu
2026-03-26 12:17:05 +08:00
parent 9a0ba45a51
commit 145bf3fa86
4 changed files with 51 additions and 28 deletions

View File

@@ -122,7 +122,7 @@ func main() {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
pprofServer, err := observability.StartPprofServer(
pprofServer, err := observability.NewPprofServer(
"Worker",
cfg.ObservabilityConfig.Pprof.Enabled,
cfg.ObservabilityConfig.Pprof.WorkerAddr,
@@ -130,13 +130,7 @@ func main() {
if err != nil {
log.Printf("Failed to start worker pprof server: %v", err)
}
defer func() {
shutdownCtx, cancel := context.WithTimeout(context.Background(), 3 * time.Second)
defer cancel()
if err := observability.Shutdown(shutdownCtx, pprofServer); err != nil {
log.Printf("Failed to shutdown worker pprof server: %v", err)
}
}()
defer pprofServer.Close()
errCh := make(chan error, 4)
log.Printf("Worker started, consuming queue=%s", socialQueue)