Skip to content

Commit

Permalink
Fix Postgres pool retry (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
MicahParks authored Jan 13, 2024
1 parent 8f906af commit 4be27c4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
9 changes: 0 additions & 9 deletions docker-compose.override.yml

This file was deleted.

11 changes: 0 additions & 11 deletions docker-compose.quickstart.yml

This file was deleted.

14 changes: 12 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 1,16 @@
version: "3"
# This file is meant for local development with the Postgres service. See the docker-compose.override.yml file.
version: "3.8"
services:
magiclinksdev:
image: "micahparks/magiclinksdevnop"
ports:
- "8080:8080"
volumes:
- "./config.quickstart.json:/config.json"
mldpostgres:
image: "postgres:15"
environment:
POSTGRES_PASSWORD: "password"
ports:
- "5432:5432"
volumes:
- "./storage/postgres/startup.sql:/docker-entrypoint-initdb.d/startup.sql"
7 changes: 5 additions & 2 deletions storage/postgres/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 135,13 @@ func pool(ctx context.Context, config Config) (*pgxpool.Pool, error) {
c.MaxConnIdleTime = config.MaxIdle.Get()
c.MinConns = config.MinConns

var conn *pgxpool.Pool
conn, err := pgxpool.NewWithConfig(ctx, c)
if err != nil {
return nil, fmt.Errorf("failed to create database connection pool: %w", err)
}
const retries = 5
for i := 0; i < retries; i {
conn, err = pgxpool.NewWithConfig(ctx, c)
err = conn.Ping(ctx)
if err != nil {
select {
case <-ctx.Done():
Expand Down

0 comments on commit 4be27c4

Please sign in to comment.