switch to using pgx pool
parent
e888a506e7
commit
4d460aa318
|
|
@ -11,7 +11,7 @@ import (
|
|||
"git.vdhsn.com/barretthousen/barretthousen/src/catalog/internal/data/postgres"
|
||||
"git.vdhsn.com/barretthousen/barretthousen/src/lib/domain/catalog"
|
||||
"git.vdhsn.com/barretthousen/barretthousen/src/lib/kernel"
|
||||
"github.com/jackc/pgx/v4"
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
"go.uber.org/dig"
|
||||
|
||||
_ "embed"
|
||||
|
|
@ -58,13 +58,13 @@ func (app *catalogApp) Start(ctx context.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err = ioc.Provide(func(pgCfg kernel.PostgresConnection) (*pgx.Conn, error) {
|
||||
if err = ioc.Provide(func(pgCfg kernel.PostgresConnection) (*pgxpool.Pool, error) {
|
||||
return kernel.NewDBConnection(ctx, pgCfg)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = ioc.Provide(func(pgConn *pgx.Conn) *postgres.Queries {
|
||||
if err = ioc.Provide(func(pgConn *pgxpool.Pool) *postgres.Queries {
|
||||
return postgres.New(pgConn)
|
||||
}); err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -114,7 +114,8 @@ func (domain Domain) FindNewUpcoming(ctx context.Context, in FindNewUpcomingInpu
|
|||
count++
|
||||
a := auction
|
||||
errGroup.Go(func() error {
|
||||
return domain.CatalogService.UpdateUpcomingAuction(ctx, a)
|
||||
domain.CatalogService.UpdateUpcomingAuction(ctx, a)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v4"
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
_ "github.com/jackc/pgx/v4/stdlib"
|
||||
"github.com/pressly/goose/v3"
|
||||
|
|
@ -30,18 +29,15 @@ func (pc PostgresConnection) String() string {
|
|||
}
|
||||
|
||||
func NewDBConnection(ctx context.Context, pg PostgresConnection) (conn *pgxpool.Pool, err error) {
|
||||
cfg, err := pgx.ParseConfig(pg.String())
|
||||
cfg, err := pgxpool.ParseConfig(pg.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cfg.MaxConns = 30
|
||||
|
||||
for retries := 0; retries < 5; retries++ {
|
||||
|
||||
if conn, err = pgxpool.ConnectConfig(ctx, &pgxpool.Config{
|
||||
MaxConns: 30,
|
||||
MaxConnLifetime: time.Second * 30,
|
||||
ConnConfig: cfg,
|
||||
}); err != nil {
|
||||
if conn, err = pgxpool.ConnectConfig(ctx, cfg); err != nil {
|
||||
sleepTime := time.Second * time.Duration(retries)
|
||||
log.Printf("%d attempt(s) to postgres failed, retrying in %v: %v", retries+1, sleepTime, err)
|
||||
time.Sleep(sleepTime)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import (
|
|||
"git.vdhsn.com/barretthousen/barretthousen/src/runner/internal"
|
||||
"git.vdhsn.com/barretthousen/barretthousen/src/runner/internal/data"
|
||||
"git.vdhsn.com/barretthousen/barretthousen/src/runner/internal/data/postgres"
|
||||
"github.com/jackc/pgx/v4"
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
"go.uber.org/dig"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
|
|
@ -64,13 +64,13 @@ func (app *RunnerApp) Start(ctx context.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err = ioc.Provide(func(pgCfg kernel.PostgresConnection) (*pgx.Conn, error) {
|
||||
if err = ioc.Provide(func(pgCfg kernel.PostgresConnection) (*pgxpool.Pool, error) {
|
||||
return kernel.NewDBConnection(ctx, pgCfg)
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = ioc.Provide(func(pgConn *pgx.Conn) *postgres.Queries {
|
||||
if err = ioc.Provide(func(pgConn *pgxpool.Pool) *postgres.Queries {
|
||||
return postgres.New(pgConn)
|
||||
}); err != nil {
|
||||
return err
|
||||
|
|
|
|||
Loading…
Reference in New Issue