Skip to content

Commit

Permalink
✨ Max DB connections setting.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Ortel <jortel@redhat.com>
  • Loading branch information
jortel committed Oct 16, 2024
1 parent 72fd8df commit 42c0570
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 8 additions & 0 deletions database/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ func Open(enforceFKs bool) (db *gorm.DB, err error) {
err = liberr.Wrap(err)
return
}
if Settings.DB.MaxConnection > 0 {
dbx, nErr := db.DB()
if nErr != nil {
err = liberr.Wrap(nErr)
return
}
dbx.SetMaxOpenConns(Settings.DB.MaxConnection)
}
err = db.AutoMigrate(model.PK{}, model.Setting{})
if err != nil {
err = liberr.Wrap(err)
Expand Down
15 changes: 12 additions & 3 deletions settings/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
const (
EnvNamespace = "NAMESPACE"
EnvDbPath = "DB_PATH"
EnvDbMaxCon = "DB_MAX_CONNECTION"
EnvDbSeedPath = "DB_SEED_PATH"
EnvBucketPath = "BUCKET_PATH"
EnvRwxSupported = "RWX_SUPPORTED"
Expand Down Expand Up @@ -45,8 +46,9 @@ type Hub struct {
Namespace string
// DB settings.
DB struct {
Path string
SeedPath string
Path string
MaxConnection int
SeedPath string
}
// Bucket settings.
Bucket struct {
Expand Down Expand Up @@ -127,6 +129,13 @@ func (r *Hub) Load() (err error) {
if !found {
r.DB.Path = "/tmp/tackle.db"
}
s, found := os.LookupEnv(EnvDbMaxCon)
if found {
n, _ := strconv.Atoi(s)
r.DB.MaxConnection = n
} else {
r.DB.MaxConnection = 1
}
r.DB.SeedPath, found = os.LookupEnv(EnvDbSeedPath)
if !found {
r.DB.SeedPath = "/tmp/seed"
Expand All @@ -135,7 +144,7 @@ func (r *Hub) Load() (err error) {
if !found {
r.Bucket.Path = "/tmp/bucket"
}
s, found := os.LookupEnv(EnvRwxSupported)
s, found = os.LookupEnv(EnvRwxSupported)
if found {
b, _ := strconv.ParseBool(s)
r.Cache.RWX = b
Expand Down

0 comments on commit 42c0570

Please sign in to comment.