Skip to content

Commit

Permalink
Merge pull request #27 from Shawn-Huang-Tron/master
Browse files Browse the repository at this point in the history
fix: read and write timeout change to be an env
  • Loading branch information
laocheng-cheng committed Nov 16, 2022
2 parents 2f4d191 + 6fb3709 commit 1c9a0fb
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions env/db/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ import (
"go.uber.org/zap"
)

const (
DBReadTimeout = 5 * time.Minute
DBWriteTimeout = 1 * time.Minute
)

var (
DBReadURL string // https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
DBWriteURL string
DBMigrationsDir = "./migrations"
DBReadTimeout = 5 * time.Minute
DBWriteTimeout = 1 * time.Minute
DBStmtTimeout = 10 * time.Second
DBNumConns = 0 // max db conns, 0 = use driver-recommended default
readUserName string
Expand Down Expand Up @@ -129,6 +126,20 @@ func init() {
DBStmtTimeout = time.Duration(toInt) * time.Second
}
}
if envKey, dbrt := env.GetEnv("DB_READ_TIMEOUT"); dbrt != "" {
if toInt, err := strconv.ParseInt(dbrt, 10, 64); err != nil {
log.Warn(constant.IntConversionError, zap.String("env", envKey), zap.Error(err))
} else {
DBReadTimeout = time.Duration(toInt) * time.Second
}
}
if envKey, dbwt := env.GetEnv("DB_WRITE_TIMEOUT"); dbwt != "" {
if toInt, err := strconv.ParseInt(dbwt, 10, 64); err != nil {
log.Warn(constant.IntConversionError, zap.String("env", envKey), zap.Error(err))
} else {
DBWriteTimeout = time.Duration(toInt) * time.Second
}
}
if envKey, dbnc := env.GetEnv("DB_NUM_CONNS"); dbnc != "" {
if toInt, err := strconv.ParseInt(dbnc, 10, 64); err != nil {
log.Warn(constant.IntConversionError, zap.String("env", envKey), zap.Error(err))
Expand Down

0 comments on commit 1c9a0fb

Please sign in to comment.