mirror of
https://github.com/ManyakRus/starter.git
synced 2025-11-29 23:38:14 +02:00
сделал DB.PingContext()
This commit is contained in:
@@ -440,7 +440,7 @@ func GetConnection_WithApplicationName(ApplicationName string) *gorm.DB {
|
|||||||
|
|
||||||
// ping_go - делает пинг каждые 60 секунд, и реконнект
|
// ping_go - делает пинг каждые 60 секунд, и реконнект
|
||||||
func ping_go() {
|
func ping_go() {
|
||||||
var err error
|
//var err error
|
||||||
|
|
||||||
ticker := time.NewTicker(60 * time.Second)
|
ticker := time.NewTicker(60 * time.Second)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
@@ -455,8 +455,21 @@ loop:
|
|||||||
log.Warn("Context app is canceled. postgres_gorm.ping")
|
log.Warn("Context app is canceled. postgres_gorm.ping")
|
||||||
break loop
|
break loop
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
|
//ping в базе данных
|
||||||
|
DB, err := Conn.DB()
|
||||||
|
if err != nil {
|
||||||
|
NeedReconnect = true
|
||||||
|
log.Error("Conn.DB() error: ", err)
|
||||||
|
} else {
|
||||||
|
err = DB.PingContext(contextmain.GetContext())
|
||||||
|
if err != nil {
|
||||||
|
NeedReconnect = true
|
||||||
|
log.Error("DB.PingContext() error: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//ping порта
|
||||||
err = port_checker.CheckPort_err(Settings.DB_HOST, Settings.DB_PORT)
|
err = port_checker.CheckPort_err(Settings.DB_HOST, Settings.DB_PORT)
|
||||||
//log.Debug("ticker, ping err: ", err) //удалить
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
NeedReconnect = true
|
NeedReconnect = true
|
||||||
log.Warn("postgres_gorm CheckPort(", addr, ") error: ", err)
|
log.Warn("postgres_gorm CheckPort(", addr, ") error: ", err)
|
||||||
|
|||||||
@@ -361,8 +361,21 @@ loop:
|
|||||||
log.Warn("Context app is canceled. postgres_pgx.ping")
|
log.Warn("Context app is canceled. postgres_pgx.ping")
|
||||||
break loop
|
break loop
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
|
//IsClosed
|
||||||
|
if Conn.IsClosed() == true {
|
||||||
|
NeedReconnect = true
|
||||||
|
log.Error("postgres_pgx error: IsClosed() = true")
|
||||||
|
}
|
||||||
|
|
||||||
|
//ping в базе данных
|
||||||
|
err = Conn.Ping(contextmain.GetContext())
|
||||||
|
if err != nil {
|
||||||
|
NeedReconnect = true
|
||||||
|
log.Error("postgres_pgx Ping() error: ", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
//ping порта
|
||||||
err = port_checker.CheckPort_err(Settings.DB_HOST, Settings.DB_PORT)
|
err = port_checker.CheckPort_err(Settings.DB_HOST, Settings.DB_PORT)
|
||||||
//log.Debug("ticker, ping err: ", err) //удалить
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
NeedReconnect = true
|
NeedReconnect = true
|
||||||
log.Warn("postgres_pgx CheckPort(", addr, ") error: ", err)
|
log.Warn("postgres_pgx CheckPort(", addr, ") error: ", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user