mirror of
https://github.com/vcscsvcscs/GenerationsHeritage.git
synced 2025-08-13 06:19:05 +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),
|
||||
)
|
||||
|
@@ -59,7 +59,7 @@ func init() { //nolint:gochecknoinits // this is a main package, init is ok
|
||||
memgraphPass = viper.GetString("MEMGRAPH_PASS")
|
||||
production = viper.GetBool("PRODUCTION")
|
||||
requestTimeout = time.Duration(viper.GetInt("REQUEST_TIMEOUT")) * time.Second
|
||||
dbOpTimeout = time.Duration(viper.GetInt("DB_OP_TIMEOUT")) * time.Millisecond
|
||||
dbOpTimeout = time.Duration(viper.GetInt("DB_OP_TIMEOUT")) * time.Second
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@@ -30,13 +30,13 @@ const (
|
||||
|
||||
// Admin defines model for Admin.
|
||||
type Admin struct {
|
||||
End *string `json:"end,omitempty"`
|
||||
Id *int `json:"id,omitempty"`
|
||||
Label *string `json:"label,omitempty"`
|
||||
Properties *struct {
|
||||
End *string `json:"End,omitempty"`
|
||||
Id *int `json:"Id,omitempty"`
|
||||
Label *string `json:"Label,omitempty"`
|
||||
Props *struct {
|
||||
Added *int `json:"added,omitempty"`
|
||||
} `json:"properties,omitempty"`
|
||||
Start *string `json:"start,omitempty"`
|
||||
} `json:"Props,omitempty"`
|
||||
Start *string `json:"Start,omitempty"`
|
||||
}
|
||||
|
||||
// FamilyRelationship defines model for FamilyRelationship.
|
||||
@@ -55,11 +55,11 @@ type FamilyTree struct {
|
||||
|
||||
// Likes defines model for Likes.
|
||||
type Likes struct {
|
||||
End *string `json:"end,omitempty"`
|
||||
Id *int `json:"id,omitempty"`
|
||||
Label *string `json:"label,omitempty"`
|
||||
Properties *LikesProperties `json:"properties,omitempty"`
|
||||
Start *string `json:"start,omitempty"`
|
||||
End *string `json:"End,omitempty"`
|
||||
Id *int `json:"Id,omitempty"`
|
||||
Label *string `json:"Label,omitempty"`
|
||||
Props *LikesProperties `json:"Props,omitempty"`
|
||||
Start *string `json:"Start,omitempty"`
|
||||
}
|
||||
|
||||
// LikesProperties defines model for LikesProperties.
|
||||
@@ -84,10 +84,9 @@ type OptimizedPersonNode struct {
|
||||
|
||||
// Person defines model for Person.
|
||||
type Person struct {
|
||||
Id *int `json:"id,omitempty"`
|
||||
Labels *[]string `json:"labels,omitempty"`
|
||||
Properties *PersonProperties `json:"properties,omitempty"`
|
||||
Type *string `json:"type"`
|
||||
Id *int `json:"Id,omitempty"`
|
||||
Labels *[]string `json:"Labels,omitempty"`
|
||||
Props *PersonProperties `json:"Props,omitempty"`
|
||||
}
|
||||
|
||||
// PersonProperties defines model for PersonProperties.
|
||||
@@ -198,9 +197,9 @@ type PersonRegistration struct {
|
||||
|
||||
// Recipe defines model for Recipe.
|
||||
type Recipe struct {
|
||||
Id *int `json:"id,omitempty"`
|
||||
Labels *[]string `json:"labels,omitempty"`
|
||||
Properties *RecipeProperties `json:"properties,omitempty"`
|
||||
Id *int `json:"Id,omitempty"`
|
||||
Labels *[]string `json:"Labels,omitempty"`
|
||||
Props *RecipeProperties `json:"Props,omitempty"`
|
||||
}
|
||||
|
||||
// RecipeProperties defines model for RecipeProperties.
|
||||
@@ -227,12 +226,12 @@ type RecipeProperties struct {
|
||||
|
||||
// Relationship defines model for Relationship.
|
||||
type Relationship struct {
|
||||
End *int `json:"end,omitempty"`
|
||||
Id *int `json:"id,omitempty"`
|
||||
Label *string `json:"label,omitempty"`
|
||||
Properties *FamilyRelationship `json:"properties,omitempty"`
|
||||
Start *int `json:"start,omitempty"`
|
||||
Type *string `json:"type"`
|
||||
End *int `json:"End,omitempty"`
|
||||
Id *int `json:"Id,omitempty"`
|
||||
Label *string `json:"Label,omitempty"`
|
||||
Props *FamilyRelationship `json:"Props,omitempty"`
|
||||
Start *int `json:"Start,omitempty"`
|
||||
Type *string `json:"Type"`
|
||||
}
|
||||
|
||||
// GetProfileAdminsParams defines parameters for GetProfileAdmins.
|
||||
|
Reference in New Issue
Block a user