Skip to content
This repository was archived by the owner on Mar 16, 2022. It is now read-only.

Commit

Permalink
[DB] Fix restore connection worker (#1281)
Browse files Browse the repository at this point in the history
* Fix restore connection worker

* Update db.go
  • Loading branch information
EnoRage authored Nov 21, 2020
1 parent 8d14666 commit 91e36d7
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,12 @@ func New(uri, readUri string, logMode bool) (*Instance, error) {

func (i *Instance) RestoreConnectionWorker(ctx context.Context, timeout time.Duration, uri string) {
log.Info("Run PG RestoreConnectionWorker")
t := time.NewTicker(timeout)

if err := i.restoreConnection(uri); err != nil {
log.Warn("PG is still unavailable:", err)
}

select {
case <-ctx.Done():
log.Info("Ctx.Done RestoreConnectionWorker exit")
return
case <-t.C:
for {
if err := i.restoreConnection(uri); err != nil {
log.Warn("PG is still unavailable:", err)
log.Error("PG is not available now")
}
time.Sleep(timeout)
}
}

Expand All @@ -84,6 +76,8 @@ func (i *Instance) restoreConnection(uri string) error {
return err
}

log.Info("Run restoreConnection")

if err = db.Ping(); err != nil {
log.Warn("PG is not available now")
log.Warn("Trying to connect to PG...")
Expand Down

0 comments on commit 91e36d7

Please sign in to comment.