MCPcopy Create free account
hub / github.com/cortexproject/cortex / dbWait

Function dbWait

pkg/configs/db/postgres/postgres.go:52–64  ·  view source on GitHub ↗

dbWait waits for database connection to be established

(db *sql.DB)

Source from the content-addressed store, hash-verified

50
51// dbWait waits for database connection to be established
52func dbWait(db *sql.DB) error {
53 deadline := time.Now().Add(dbTimeout)
54 var err error
55 for tries := 0; time.Now().Before(deadline); tries++ {
56 err = db.Ping()
57 if err == nil {
58 return nil
59 }
60 level.Warn(util_log.Logger).Log("msg", "db connection not established, retrying...", "err", err)
61 time.Sleep(time.Second << uint(tries))
62 }
63 return errors.Wrapf(err, "db connection not established after %s", dbTimeout)
64}
65
66// New creates a new postgres DB
67func New(uri, migrationsDir string) (DB, error) {

Callers 1

NewFunction · 0.85

Calls 4

BeforeMethod · 0.80
PingMethod · 0.80
AddMethod · 0.45
LogMethod · 0.45

Tested by

no test coverage detected