Skip to content

Commit

Permalink
common: take max connections from config
Browse files Browse the repository at this point in the history
  • Loading branch information
jogramming committed Feb 25, 2020
1 parent 3004cf7 commit b3c9a23
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,10 @@ func connectDB(host, user, pass, dbName string) error {
PQ = db.DB()
boil.SetDB(PQ)
if err == nil {
PQ.SetMaxOpenConns(3)
PQ.SetMaxIdleConns(3)
maxConns := confMaxSQLConns.GetInt()
PQ.SetMaxOpenConns(maxConns)
PQ.SetMaxIdleConns(maxConns)
logger.Infof("Set max PG connections to %d", maxConns)
}
GORM.SetLogger(&GORMLogger{})

Expand Down
4 changes: 3 additions & 1 deletion common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ var (
ConfDogStatsdAddress = config.RegisterOption("yagpdb.dogstatsdaddress", "dogstatsd address", "")
confNoSchemaInit = config.RegisterOption("yagpdb.no_schema_init", "Disable schema intiialization", false)

confMaxSQLConns = config.RegisterOption("yagdb.pq_max_conns", "Max connections to postgres", 3)

BotOwners []int64
)

Expand All @@ -45,7 +47,7 @@ func LoadConfig() (err error) {
config.AddSource(&config.EnvSource{})
config.AddSource(&config.RedisConfigStore{Pool: RedisPool})
config.Load()

requiredConf := []*config.ConfigOption{
ConfClientID,
ConfClientSecret,
Expand Down

0 comments on commit b3c9a23

Please sign in to comment.