Skip to content
Snippets Groups Projects
Commit a4903fd9 authored by Manuel Heß's avatar Manuel Heß
Browse files

add retry for connection check

parent a02bd208
Branches main
No related tags found
No related merge requests found
...@@ -6,8 +6,11 @@ import ( ...@@ -6,8 +6,11 @@ import (
"fmt" "fmt"
"github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool" "github.com/jackc/pgx/v5/pgxpool"
"github.com/sethvargo/go-retry"
log "github.com/sirupsen/logrus"
entity2 "gitlab.eclipse.org/eclipse/xfsc/organisational-credential-manager-w-stack/status-list-service/internal/entity" entity2 "gitlab.eclipse.org/eclipse/xfsc/organisational-credential-manager-w-stack/status-list-service/internal/entity"
"regexp" "regexp"
"time"
) )
// TODO: queries as constants? // TODO: queries as constants?
...@@ -24,8 +27,21 @@ func newPostgresConnection(username string, password string, host string, port i ...@@ -24,8 +27,21 @@ func newPostgresConnection(username string, password string, host string, port i
return nil, err return nil, err
} }
if err = conn.Ping(context.Background()); err != nil { bf := retry.NewFibonacci(time.Millisecond * 500)
return nil, fmt.Errorf("connection check failed: %w", err) bf = retry.WithCappedDuration(time.Second*30, bf)
bf = retry.WithJitter(time.Millisecond*50, bf)
bf = retry.WithMaxDuration(time.Minute*2, bf)
if err = retry.Do(context.Background(), bf, func(_ context.Context) error {
if err = conn.Ping(context.Background()); err != nil {
err = fmt.Errorf("connection check failed: %w", err)
log.Error(err)
err = retry.RetryableError(err)
return err
}
return nil
}); err != nil {
return nil, err
} }
return &postgresConnection{ return &postgresConnection{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment