mirror of
https://github.com/GMWalletApp/epusdt.git
synced 2026-07-07 18:26:16 +00:00
修改数据库连接失败挂起的逻辑为10s后重试
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/assimon/luuu/util/log"
|
||||
"github.com/gookit/color"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
@@ -36,7 +35,11 @@ func PostgreSQLInit() {
|
||||
},
|
||||
)
|
||||
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 {
|
||||
@@ -45,7 +48,10 @@ func PostgreSQLInit() {
|
||||
sqlDB, err := Mdb.DB()
|
||||
if err != nil {
|
||||
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.SetMaxOpenConns(viper.GetInt("postgres_max_open_conns"))
|
||||
@@ -53,7 +59,10 @@ func PostgreSQLInit() {
|
||||
err = sqlDB.Ping()
|
||||
if err != nil {
|
||||
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")
|
||||
}
|
||||
|
||||
@@ -3,11 +3,12 @@ package dao
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/assimon/luuu/util/log"
|
||||
"github.com/go-redis/redis/v8"
|
||||
"github.com/gookit/color"
|
||||
"github.com/spf13/viper"
|
||||
"time"
|
||||
)
|
||||
|
||||
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.")
|
||||
} else if err != nil {
|
||||
color.Red.Printf("[store_redis] redis connRdb err,err=%s", err)
|
||||
panic(err)
|
||||
// panic(err)
|
||||
time.Sleep(10 * time.Second)
|
||||
RedisInit()
|
||||
return
|
||||
} else {
|
||||
log.Sugar.Debug("[store_redis] redis connRdb success,suc=%s", pong)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user