rename maxRetries minRetryBackoff maxRetryBackoff to backoffMaxRetries backOffMinInterval backOffMaxInterval. to be consistent with other components
This commit is contained in:
parent
280f810047
commit
ddbb039210
|
@ -19,13 +19,13 @@ type metadata struct {
|
|||
|
||||
// Maximum number of retries before giving up.
|
||||
// Default is to not retry failed commands.
|
||||
maxRetries int
|
||||
backoffMaxRetries int
|
||||
// Minimum backoff between each retry.
|
||||
// Default is 8 milliseconds; -1 disables backoff.
|
||||
minRetryBackoff time.Duration
|
||||
backOffMinInterval time.Duration
|
||||
// Maximum backoff between each retry.
|
||||
// Default is 512 milliseconds; -1 disables backoff.
|
||||
maxRetryBackoff time.Duration
|
||||
backOffMaxInterval time.Duration
|
||||
|
||||
// Dial timeout for establishing new connections.
|
||||
dialTimeout time.Duration
|
||||
|
|
|
@ -23,9 +23,9 @@ const (
|
|||
host = "redisHost"
|
||||
password = "redisPassword"
|
||||
db = "redisDB"
|
||||
maxRetries = "maxRetries"
|
||||
minRetryBackoff = "minRetryBackoff"
|
||||
maxRetryBackoff = "maxRetryBackoff"
|
||||
backoffMaxRetries = "backoffMaxRetries"
|
||||
backOffMinInterval = "backOffMinInterval"
|
||||
backOffMaxInterval = "backOffMaxInterval"
|
||||
dialTimeout = "dialTimeout"
|
||||
readTimeout = "readTimeout"
|
||||
writeTimeout = "writeTimeout"
|
||||
|
@ -150,35 +150,35 @@ func parseRedisMetadata(meta pubsub.Metadata) (metadata, error) {
|
|||
m.concurrency = uint(concurrency)
|
||||
}
|
||||
|
||||
if val, ok := meta.Properties[maxRetries]; ok && val != "" {
|
||||
maxRetries, err := strconv.Atoi(val)
|
||||
if val, ok := meta.Properties[backoffMaxRetries]; ok && val != "" {
|
||||
backoffMaxRetries, err := strconv.Atoi(val)
|
||||
if err != nil {
|
||||
return m, fmt.Errorf("redis streams error: can't parse maxRetries field: %s", err)
|
||||
return m, fmt.Errorf("redis streams error: can't parse backoffMaxRetries field: %s", err)
|
||||
}
|
||||
m.maxRetries = maxRetries
|
||||
m.backoffMaxRetries = backoffMaxRetries
|
||||
}
|
||||
|
||||
if val, ok := meta.Properties[minRetryBackoff]; ok && val != "" {
|
||||
if val, ok := meta.Properties[backOffMinInterval]; ok && val != "" {
|
||||
if val == "-1" {
|
||||
m.minRetryBackoff = -1
|
||||
} else if minRetryBackoffMs, err := strconv.ParseUint(val, 10, 64); err == nil {
|
||||
m.minRetryBackoff = time.Duration(minRetryBackoffMs) * time.Millisecond
|
||||
m.backOffMinInterval = -1
|
||||
} else if backOffMinIntervalMs, err := strconv.ParseUint(val, 10, 64); err == nil {
|
||||
m.backOffMinInterval = time.Duration(backOffMinIntervalMs) * time.Millisecond
|
||||
} else if d, err := time.ParseDuration(val); err == nil {
|
||||
m.minRetryBackoff = d
|
||||
m.backOffMinInterval = d
|
||||
} else {
|
||||
return m, fmt.Errorf("redis streams error: invalid minRetryBackoff %s, %s", val, err)
|
||||
return m, fmt.Errorf("redis streams error: invalid backOffMinInterval %s, %s", val, err)
|
||||
}
|
||||
}
|
||||
|
||||
if val, ok := meta.Properties[maxRetryBackoff]; ok && val != "" {
|
||||
if val, ok := meta.Properties[backOffMaxInterval]; ok && val != "" {
|
||||
if val == "-1" {
|
||||
m.maxRetryBackoff = -1
|
||||
} else if maxRetryBackoffMs, err := strconv.ParseUint(val, 10, 64); err == nil {
|
||||
m.maxRetryBackoff = time.Duration(maxRetryBackoffMs) * time.Millisecond
|
||||
m.backOffMaxInterval = -1
|
||||
} else if backOffMaxIntervalMs, err := strconv.ParseUint(val, 10, 64); err == nil {
|
||||
m.backOffMaxInterval = time.Duration(backOffMaxIntervalMs) * time.Millisecond
|
||||
} else if d, err := time.ParseDuration(val); err == nil {
|
||||
m.maxRetryBackoff = d
|
||||
m.backOffMaxInterval = d
|
||||
} else {
|
||||
return m, fmt.Errorf("redis streams error: invalid maxRetryBackoff %s, %s", val, err)
|
||||
return m, fmt.Errorf("redis streams error: invalid backOffMaxInterval %s, %s", val, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -288,9 +288,9 @@ func (r *redisStreams) Init(metadata pubsub.Metadata) error {
|
|||
Addr: m.host,
|
||||
Password: m.password,
|
||||
DB: m.db,
|
||||
MaxRetries: m.maxRetries,
|
||||
MaxRetryBackoff: m.maxRetryBackoff,
|
||||
MinRetryBackoff: m.minRetryBackoff,
|
||||
MaxRetries: m.backoffMaxRetries,
|
||||
MaxRetryBackoff: m.backOffMaxInterval,
|
||||
MinRetryBackoff: m.backOffMinInterval,
|
||||
DialTimeout: m.dialTimeout,
|
||||
ReadTimeout: m.readTimeout,
|
||||
WriteTimeout: m.writeTimeout,
|
||||
|
|
|
@ -32,9 +32,9 @@ func getFakeProperties() map[string]string {
|
|||
poolSize: "20",
|
||||
maxConnAge: "200s",
|
||||
db: "1",
|
||||
maxRetries: "1",
|
||||
minRetryBackoff: "8ms",
|
||||
maxRetryBackoff: "1s",
|
||||
backoffMaxRetries: "1",
|
||||
backOffMinInterval: "8ms",
|
||||
backOffMaxInterval: "1s",
|
||||
minIdleConns: "1",
|
||||
poolTimeout: "1s",
|
||||
idleTimeout: "1s",
|
||||
|
@ -65,9 +65,9 @@ func TestParseRedisMetadata(t *testing.T) {
|
|||
assert.Equal(t, 20, m.poolSize)
|
||||
assert.Equal(t, 200*time.Second, m.maxConnAge)
|
||||
assert.Equal(t, 1, m.db)
|
||||
assert.Equal(t, 1, m.maxRetries)
|
||||
assert.Equal(t, 8*time.Millisecond, m.minRetryBackoff)
|
||||
assert.Equal(t, 1*time.Second, m.maxRetryBackoff)
|
||||
assert.Equal(t, 1, m.backoffMaxRetries)
|
||||
assert.Equal(t, 8*time.Millisecond, m.backOffMinInterval)
|
||||
assert.Equal(t, 1*time.Second, m.backOffMaxInterval)
|
||||
assert.Equal(t, 1, m.minIdleConns)
|
||||
assert.Equal(t, 1*time.Second, m.poolTimeout)
|
||||
assert.Equal(t, 1*time.Second, m.idleTimeout)
|
||||
|
@ -118,8 +118,8 @@ func TestParseRedisMetadata(t *testing.T) {
|
|||
fakeMetaData.Properties[readTimeout] = "-1"
|
||||
fakeMetaData.Properties[idleTimeout] = "-1"
|
||||
fakeMetaData.Properties[idleCheckFrequency] = "-1"
|
||||
fakeMetaData.Properties[maxRetryBackoff] = "-1"
|
||||
fakeMetaData.Properties[minRetryBackoff] = "-1"
|
||||
fakeMetaData.Properties[backOffMaxInterval] = "-1"
|
||||
fakeMetaData.Properties[backOffMinInterval] = "-1"
|
||||
|
||||
// act
|
||||
m, err := parseRedisMetadata(fakeMetaData)
|
||||
|
@ -128,8 +128,8 @@ func TestParseRedisMetadata(t *testing.T) {
|
|||
assert.True(t, m.readTimeout == -1)
|
||||
assert.True(t, m.idleTimeout == -1)
|
||||
assert.True(t, m.idleCheckFrequency == -1)
|
||||
assert.True(t, m.maxRetryBackoff == -1)
|
||||
assert.True(t, m.minRetryBackoff == -1)
|
||||
assert.True(t, m.backOffMaxInterval == -1)
|
||||
assert.True(t, m.backOffMinInterval == -1)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue