Skip to content

Commit

Permalink
Enhance backoff logic. Replace Nodes output with pocket-go package one.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecuesta committed Apr 15, 2024
1 parent d8da76b commit bb5c619
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
4 changes: 3 additions & 1 deletion packages/go/pocket_rpc/client_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func (cp *ClientPool) DoRRLoadBalanced(req *http.Request, timeout time.Duration)
backoff := NewBackoff(cp.opts.MinBackoff, cp.opts.MaxBackoff) // adjust min and max duration as necessary
clients := len(cp.clients)
allowBackoff := clients >= cp.opts.MaxRetries
backoffCounter := 0

for {
if retries >= cp.opts.MaxRetries {
Expand All @@ -94,7 +95,8 @@ func (cp *ClientPool) DoRRLoadBalanced(req *http.Request, timeout time.Duration)

if allowBackoff && retries > clients {
// apply backoff only when the retries are more than the available clients
time.Sleep(backoff.Duration(retries))
time.Sleep(backoff.Duration(backoffCounter))
backoffCounter++
}

client := cp.getClient()
Expand Down
10 changes: 2 additions & 8 deletions packages/go/pocket_rpc/pocket_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@ type PocketRpc struct {
pageSize int
}

type NodesQueryResponse struct {
Result []*poktGoSdk.Node `json:"result"`
Page int `json:"page"`
TotalPages int `json:"total_pages"`
}

type NodesPageChannelResponse struct {
Data *NodesQueryResponse
Data *poktGoSdk.GetNodesOutput
Error error
}

Expand Down Expand Up @@ -168,7 +162,7 @@ func (rpc *PocketRpc) getNodesByPage(height int64, service string, page int, pag
}
}(resp.Body)

chResponse.Data, chResponse.Error = readResponse[NodesQueryResponse](resp)
chResponse.Data, chResponse.Error = readResponse[poktGoSdk.GetNodesOutput](resp)
}

func (rpc *PocketRpc) GetNodes(height int64, service string) (nodes []*poktGoSdk.Node, e error) {
Expand Down

0 comments on commit bb5c619

Please sign in to comment.