Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from Cox-Automotive/feature/US956382_backoff_re…
Browse files Browse the repository at this point in the history
…try_for_kafka

Added Exponential backoff retry to resourceTopicCreate
  • Loading branch information
Manases-Leal committed Nov 16, 2022
2 parents 5ba6919 + 111b74a commit 5905154
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions client/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"net/http"
"strconv"
"time"
"math"
)

type Topics struct {
Expand Down Expand Up @@ -149,10 +151,23 @@ func createTopic(c Client, t *NewTopic) (*Topic, error) {
return nil, err
}

res, err := c.doRequest(req)
if err != nil {
return nil, err
}
retryCap := 3
res, err := c.doRequest(req)
for retry := 1; retry <= retryCap; retry++{
if err != nil {
fmt.Errorf("%s\n",err)
fmt.Println("Waiting to retry...")
time.Sleep(time.Duration(math.Pow(float64(retry), 2)) * time.Second)
fmt.Printf("Starting retry attempt %d of %d\n", retry, retryCap)
res, err := c.doRequest(req)
_,_ = res, err
} else {
break
}
}
if err != nil {
return nil, err
}

var topic Topic
err = json.Unmarshal(res, &topic)
Expand Down

0 comments on commit 5905154

Please sign in to comment.