mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-11 11:43:46 +08:00
增加链路追踪配置,优化服务退出流程,gf版本升级到v2.4.2
This commit is contained in:
@@ -7,7 +7,9 @@ package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/os/gproc"
|
||||
"hotgo/internal/consts"
|
||||
"hotgo/utility/simple"
|
||||
"os"
|
||||
"sync"
|
||||
@@ -16,15 +18,27 @@ import (
|
||||
var (
|
||||
serverCloseSignal = make(chan struct{}, 1)
|
||||
serverWg = sync.WaitGroup{}
|
||||
once sync.Once
|
||||
)
|
||||
|
||||
// signalHandlerForOverall 关闭信号处理
|
||||
func signalHandlerForOverall(sig os.Signal) {
|
||||
serverCloseSignal <- struct{}{}
|
||||
serverCloseEvent(gctx.GetInitCtx())
|
||||
}
|
||||
|
||||
// signalListen 信号监听
|
||||
func signalListen(ctx context.Context, handler ...gproc.SigHandler) {
|
||||
simple.SafeGo(ctx, func(ctx context.Context) {
|
||||
gproc.AddSigHandlerShutdown(handler...)
|
||||
gproc.Listen()
|
||||
})
|
||||
}
|
||||
|
||||
// serverCloseEvent 关闭事件
|
||||
// 区别于服务收到退出信号后的处理,只会执行一次
|
||||
func serverCloseEvent(ctx context.Context) {
|
||||
once.Do(func() {
|
||||
simple.Event().Call(consts.EventServerClose, ctx)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user