mirror of
https://github.com/vcscsvcscs/GenerationsHeritage.git
synced 2025-08-14 14:59:07 +02:00
fix db connection and timeout
This commit is contained in:
@@ -37,7 +37,7 @@ func New(
|
||||
panic("database operation timeout is required")
|
||||
}
|
||||
|
||||
return &server{db: drv, health: hc, logger: logger}
|
||||
return &server{db: drv, health: hc, logger: logger, dbOpTimeout: databaseOperationTimeout}
|
||||
}
|
||||
|
||||
func (srv *server) HealthCheck(c *gin.Context) {
|
||||
|
@@ -2,6 +2,7 @@ package memgraph
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
|
||||
"go.uber.org/zap"
|
||||
@@ -14,10 +15,23 @@ func InitDatabase(logger *zap.Logger, dbURI, dbUser, dbPassword string) neo4j.Dr
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
for attempt := 1; attempt <= 5; attempt++ {
|
||||
err = driver.VerifyConnectivity(ctx)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
|
||||
logger.Warn("Retrying connection to db...",
|
||||
zap.Error(err),
|
||||
zap.String("dbUser", dbUser),
|
||||
zap.String("dbURI", dbURI),
|
||||
zap.Int("attempt", attempt),
|
||||
)
|
||||
time.Sleep(time.Duration(attempt*5) * time.Second)
|
||||
}
|
||||
|
||||
err = driver.VerifyConnectivity(ctx)
|
||||
if err != nil {
|
||||
logger.Panic("Unable to connect to db:", zap.Error(err),
|
||||
logger.Panic("Unable to connect to db after retries:", zap.Error(err),
|
||||
zap.String("dbUser", dbUser),
|
||||
zap.String("dbURI", dbURI),
|
||||
)
|
||||
|
Reference in New Issue
Block a user