Skip to content

Commit

Permalink
Adjust based on review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tiger5226 committed Jan 24, 2020
1 parent bcec1c6 commit 9589d86
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/storage/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/volatiletech/sqlboiler/boil"
)

const maxDBConnectAttempts = 10
const maxDBConnectAttempts = 7

// Handler implements the app database handler.
type Handler interface {
Expand Down Expand Up @@ -63,14 +63,14 @@ func (c *Connection) Connect() error {
dsn := MakeDSN(c.params)
c.logger.LogF(monitor.F{"dsn": dsn}).Info("connecting to the DB")
var err error
var secondsToWait int
var db *sqlx.DB
for i := 0; i < maxDBConnectAttempts; i++ {
db, err = sqlx.Connect(c.dialect, dsn)
if err == nil {
break
}
secondsToWait = secondsToWait + i + 1
secondsToWait := i + 1
c.logger.Log().Warning("Database Connection Err: ", err)
c.logger.Log().Warningf("Attempt %d - could not connect to database...retry in %d seconds", i, secondsToWait)
time.Sleep(time.Duration(secondsToWait) * time.Second)
}
Expand Down

0 comments on commit 9589d86

Please sign in to comment.