Jelajahi Sumber

Add ExponentialReconnectionPolicy.MaxInterval (#1407)

Allow specifying MaxInterval for exponential reconnection policy.
Ingo Oeser 5 tahun lalu
induk
melakukan
ae7adae99b
1 mengubah file dengan 6 tambahan dan 1 penghapusan
  1. 6 1
      policies.go

+ 6 - 1
policies.go

@@ -953,10 +953,15 @@ func (c *ConstantReconnectionPolicy) GetMaxRetries() int {
 type ExponentialReconnectionPolicy struct {
 	MaxRetries      int
 	InitialInterval time.Duration
+	MaxInterval     time.Duration
 }
 
 func (e *ExponentialReconnectionPolicy) GetInterval(currentRetry int) time.Duration {
-	return getExponentialTime(e.InitialInterval, math.MaxInt16*time.Second, currentRetry)
+	max := e.MaxInterval
+	if max < e.InitialInterval {
+		max = math.MaxInt16 * time.Second
+	}
+	return getExponentialTime(e.InitialInterval, max, currentRetry)
 }
 
 func (e *ExponentialReconnectionPolicy) GetMaxRetries() int {