Skip to content

Commit

Permalink
enhance: surface redis ping errors (#1165)
Browse files Browse the repository at this point in the history
  • Loading branch information
plyr4 authored Aug 14, 2024
1 parent df7bf4a commit 8a04a89
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 1 addition & 2 deletions queue/redis/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package redis

import (
"context"
"fmt"
)

// Ping contacts the queue to test its connection.
Expand All @@ -13,7 +12,7 @@ func (c *client) Ping(ctx context.Context) error {
err := c.Redis.Ping(ctx).Err()
if err != nil {
c.Logger.Debugf("unable to ping Redis queue.")
return fmt.Errorf("unable to establish connection to Redis queue")
return err
}

return nil
Expand Down
7 changes: 5 additions & 2 deletions queue/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/alicebob/miniredis/v2"
"github.com/pkg/errors"
"github.com/redis/go-redis/v9"
"github.com/sirupsen/logrus"

Expand Down Expand Up @@ -151,9 +152,10 @@ func failoverFromOptions(source *redis.Options) *redis.FailoverOptions {
// we try to set it up.
func pingQueue(c *client) error {
// attempt 10 times
var err error
for i := 0; i < 10; i++ {
// send ping request to client
err := c.Redis.Ping(context.Background()).Err()
err = c.Redis.Ping(context.Background()).Err()
if err != nil {
c.Logger.Debugf("unable to ping Redis queue. Retrying in %v", time.Duration(i)*time.Second)
time.Sleep(1 * time.Second)
Expand All @@ -164,7 +166,8 @@ func pingQueue(c *client) error {
return nil
}

return fmt.Errorf("unable to establish connection to Redis queue")
// capture last seen non-nil error
return errors.Wrap(err, "unable to establish connection to Redis queue")
}

// NewTest returns a Queue implementation that
Expand Down

0 comments on commit 8a04a89

Please sign in to comment.