Skip to content

Commit 4f6f01c

Browse files
author
Feroze Mohideen
authored
add retry to apply (#4031)
1 parent f1de586 commit 4f6f01c

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

api/client/api.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,20 @@ func (c *Client) getRequest(relPath string, data interface{}, response interface
153153
}
154154

155155
type postRequestOpts struct {
156+
// retryCount is the number of times to retry the request
156157
retryCount uint
158+
// onlyRetry500 will only retry the request if the status code is in the 500-range
159+
onlyRetry500 bool
157160
}
158161

159162
func (c *Client) postRequest(relPath string, data interface{}, response interface{}, opts ...postRequestOpts) error {
160163
var retryCount uint = 1
164+
var onlyRetry500 bool = false
161165

162166
if len(opts) > 0 {
163167
for _, opt := range opts {
164168
retryCount = opt.retryCount
169+
onlyRetry500 = opt.onlyRetry500
165170
}
166171
}
167172

@@ -191,6 +196,10 @@ func (c *Client) postRequest(relPath string, data interface{}, response interfac
191196

192197
if i != int(retryCount)-1 {
193198
if httpErr != nil {
199+
if onlyRetry500 && httpErr.Code < 500 {
200+
// if we only retry 500-range responses and this is not a 500-range response, do not retry, instead return the error
201+
return fmt.Errorf("%v", httpErr.Error)
202+
}
194203
fmt.Fprintf(os.Stderr, "Error: %s (status code %d), retrying request...\n", httpErr.Error, httpErr.Code)
195204
} else {
196205
fmt.Fprintf(os.Stderr, "Error: %v, retrying request...\n", err)

api/client/porter_app.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ func (c *Client) ApplyPorterApp(
253253
),
254254
req,
255255
resp,
256+
postRequestOpts{
257+
retryCount: 3,
258+
onlyRetry500: true,
259+
},
256260
)
257261

258262
return resp, err

0 commit comments

Comments
 (0)