| 123456789101112131415161718192021222324252627282930313233343536373839 |
- package bootstraps
-
- // import (
- // "os"
- // "os/signal"
- // "syscall"
- // "time"
-
- // "git.x2erp.com/qdy/go-base/logger"
- // "git.x2erp.com/qdy/go-db/factory/database"
- // )
-
- // // setupGracefulShutdown 设置优雅关闭
- // func SetupGracefulShutdown(dbFactory *database.DBFactory, cleanupFuncs ...func()) {
- // signalCh := make(chan os.Signal, 1)
- // signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM)
-
- // go func() {
- // <-signalCh
- // logger.Info("\n接收到关闭信号,正在优雅关闭...")
-
- // // 关闭数据库连接
- // if dbFactory != nil {
- // if err := dbFactory.Close(); err != nil {
- // logger.Error("关闭数据库错误: %v", err)
- // }
- // logger.Info("数据库连接已关闭")
- // }
-
- // // 执行其他清理函数
- // for _, cleanup := range cleanupFuncs {
- // cleanup()
- // }
-
- // // 等待日志写入完成
- // time.Sleep(100 * time.Millisecond)
- // os.Exit(0)
- // }()
- // }
|