MCPcopy
hub / github.com/PatchMon/PatchMon / waitForDB

Method waitForDB

server-source-code/internal/database/database.go:45–64  ·  view source on GitHub ↗

waitForDB retries connection until DB is available.

(ctx context.Context)

Source from the content-addressed store, hash-verified

43
44// waitForDB retries connection until DB is available.
45func (p *Pool) waitForDB(ctx context.Context) error {
46 maxAttempts := p.cfg.DBConnMaxAttempts
47 interval := time.Duration(p.cfg.DBConnWaitInterval) * time.Second
48
49 for attempt := 1; attempt <= maxAttempts; attempt++ {
50 if err := p.Ping(ctx); err == nil {
51 return nil
52 }
53
54 if attempt < maxAttempts {
55 select {
56 case <-ctx.Done():
57 return ctx.Err()
58 case <-time.After(interval):
59 }
60 }
61 }
62
63 return fmt.Errorf("database unavailable after %d attempts", maxAttempts)
64}
65
66// Ping checks database connectivity.
67func (p *Pool) Ping(ctx context.Context) error {

Callers 1

NewPoolFunction · 0.95

Calls 1

PingMethod · 0.95

Tested by

no test coverage detected