MCPcopy Index your code
hub / github.com/PatchMon/PatchMon / waitForDB

Method waitForDB

server-source-code/internal/database/db.go:96–115  ·  view source on GitHub ↗

waitForDB retries connection until DB is available.

(ctx context.Context)

Source from the content-addressed store, hash-verified

94
95// waitForDB retries connection until DB is available.
96func (d *DB) waitForDB(ctx context.Context) error {
97 maxAttempts := d.cfg.DBConnMaxAttempts
98 interval := time.Duration(d.cfg.DBConnWaitInterval) * time.Second
99
100 for attempt := 1; attempt <= maxAttempts; attempt++ {
101 if err := d.pool.Ping(ctx); err == nil {
102 return nil
103 }
104
105 if attempt < maxAttempts {
106 select {
107 case <-ctx.Done():
108 return ctx.Err()
109 case <-time.After(interval):
110 }
111 }
112 }
113
114 return fmt.Errorf("database unavailable after %d attempts", maxAttempts)
115}
116
117// DB returns the receiver, satisfying DBProvider for single-host mode.
118func (d *DB) DB(ctx context.Context) *DB {

Callers 1

NewDBFunction · 0.95

Calls 1

PingMethod · 0.45

Tested by

no test coverage detected