Skip to content

Commit

Permalink
cleaning code
Browse files Browse the repository at this point in the history
  • Loading branch information
fcarrero committed Oct 26, 2022
1 parent 5a4415c commit 23a39ac
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions middleware_retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/google/martian/log"
"math"
"math/rand"
"time"
Expand Down Expand Up @@ -117,9 +118,9 @@ func incrementRetry(message *Msg) (retryCount int) {
}

func secondsToDelay(count int, retryOptions map[string]interface{}) int {
log.Infof("secondsToDelay", "count", count)
exp := float64(4)
minDelay := float64(15)
//maxDelay := math.Inf(1)
maxRand := float64(30)
if retryOptions != nil {
if v, ok := retryOptions["exp"].(json.Number); ok {
Expand All @@ -132,12 +133,7 @@ func secondsToDelay(count int, retryOptions map[string]interface{}) int {
minDelay = v2
}
}
/*
if v, ok := retryOptions["max_delay"].(json.Number); ok {
if v2, err := v.Float64(); err == nil {
maxDelay = v2
}
}*/

if v, ok := retryOptions["max_rand"].(json.Number); ok {
if v2, err := v.Float64(); err == nil {
maxRand = v2
Expand All @@ -149,9 +145,8 @@ func secondsToDelay(count int, retryOptions map[string]interface{}) int {
if maxRand > 0 {
randN = rand.Intn(int(maxRand))
}
//(retry_count ** 4) + 15 + (rand(30) * (retry_count + 1))

backoffExponential := (math.Pow(float64(count), exp)) + minDelay + (float64((randN) * (count + 1)))

log.Infof("secondsToDelay", "backoffExponential", backoffExponential)
return int(backoffExponential)
}

0 comments on commit 23a39ac

Please sign in to comment.