mirror of
https://github.com/GMWalletApp/epusdt.git
synced 2026-07-07 02:06:16 +00:00
修改数据库连接失败挂起的逻辑为10s后重试
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/assimon/luuu/util/log"
|
"github.com/assimon/luuu/util/log"
|
||||||
"github.com/gookit/color"
|
"github.com/gookit/color"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
"gorm.io/driver/postgres"
|
"gorm.io/driver/postgres"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"gorm.io/gorm/logger"
|
"gorm.io/gorm/logger"
|
||||||
@@ -36,7 +35,11 @@ func PostgreSQLInit() {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
color.Red.Printf("[store_db] postgres open DB,err=%s\n", err)
|
||||||
|
// panic(err)
|
||||||
|
time.Sleep(10 * time.Second)
|
||||||
|
PostgreSQLInit()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.AppDebug {
|
if config.AppDebug {
|
||||||
@@ -45,7 +48,10 @@ func PostgreSQLInit() {
|
|||||||
sqlDB, err := Mdb.DB()
|
sqlDB, err := Mdb.DB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
color.Red.Printf("[store_db] postgres get DB,err=%s\n", err)
|
color.Red.Printf("[store_db] postgres get DB,err=%s\n", err)
|
||||||
panic(err)
|
// panic(err)
|
||||||
|
time.Sleep(10 * time.Second)
|
||||||
|
PostgreSQLInit()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
sqlDB.SetMaxIdleConns(viper.GetInt("postgres_max_idle_conns"))
|
sqlDB.SetMaxIdleConns(viper.GetInt("postgres_max_idle_conns"))
|
||||||
sqlDB.SetMaxOpenConns(viper.GetInt("postgres_max_open_conns"))
|
sqlDB.SetMaxOpenConns(viper.GetInt("postgres_max_open_conns"))
|
||||||
@@ -53,7 +59,10 @@ func PostgreSQLInit() {
|
|||||||
err = sqlDB.Ping()
|
err = sqlDB.Ping()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
color.Red.Printf("[store_db] postgres connDB err:%s", err.Error())
|
color.Red.Printf("[store_db] postgres connDB err:%s", err.Error())
|
||||||
panic(err)
|
// panic(err)
|
||||||
|
time.Sleep(10 * time.Second)
|
||||||
|
PostgreSQLInit()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
log.Sugar.Debug("[store_db] postgres connDB success")
|
log.Sugar.Debug("[store_db] postgres connDB success")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ package dao
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/assimon/luuu/util/log"
|
"github.com/assimon/luuu/util/log"
|
||||||
"github.com/go-redis/redis/v8"
|
"github.com/go-redis/redis/v8"
|
||||||
"github.com/gookit/color"
|
"github.com/gookit/color"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var Rdb *redis.Client
|
var Rdb *redis.Client
|
||||||
@@ -34,7 +35,10 @@ func RedisInit() {
|
|||||||
log.Sugar.Debug("[store_redis] Nil reply returned by Rdb when key does not exist.")
|
log.Sugar.Debug("[store_redis] Nil reply returned by Rdb when key does not exist.")
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
color.Red.Printf("[store_redis] redis connRdb err,err=%s", err)
|
color.Red.Printf("[store_redis] redis connRdb err,err=%s", err)
|
||||||
panic(err)
|
// panic(err)
|
||||||
|
time.Sleep(10 * time.Second)
|
||||||
|
RedisInit()
|
||||||
|
return
|
||||||
} else {
|
} else {
|
||||||
log.Sugar.Debug("[store_redis] redis connRdb success,suc=%s", pong)
|
log.Sugar.Debug("[store_redis] redis connRdb success,suc=%s", pong)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user