-
Notifications
You must be signed in to change notification settings - Fork 0
increase timeout and retry #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| "net/http" | ||
| "net/url" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/tomnomnom/linkheader" | ||
| "google.golang.org/grpc/codes" | ||
|
|
@@ -592,11 +593,25 @@ | |
| } | ||
| req = append(req, paginationVarsToReqOptions(&pg)...) | ||
|
|
||
| next, err := c.get(ctx, fmt.Sprintf(VariableSetM2MBaseUrl, c.deployment), &resp, req...) | ||
| if err != nil { | ||
| return nil, "", err | ||
| maxRetries := 3 | ||
| baseDelay := 2 * time.Second | ||
|
|
||
| for attempt := 0; attempt < maxRetries; attempt++ { | ||
| next, err := c.get(ctx, fmt.Sprintf(VariableSetM2MBaseUrl, c.deployment), &resp, req...) | ||
| if err != nil { | ||
| if status.Code(err) == codes.DeadlineExceeded || strings.Contains(err.Error(), "timeout") || strings.Contains(err.Error(), "deadline exceeded") { | ||
| if attempt < maxRetries-1 { | ||
| delay := baseDelay * time.Duration(1<<attempt) | ||
| time.Sleep(delay) | ||
| continue | ||
| } | ||
| } | ||
| return nil, "", err | ||
|
Comment on lines
+599
to
+609
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Retry condition misses HTTP gateway/request timeouts.
Apply this diff (pattern repeated in the other two retry blocks): - if err != nil {
- if status.Code(err) == codes.DeadlineExceeded || strings.Contains(err.Error(), "timeout") || strings.Contains(err.Error(), "deadline exceeded") {
+ if err != nil {
+ code := status.Code(err)
+ if code == codes.DeadlineExceeded ||
+ code == codes.Code(http.StatusGatewayTimeout) ||
+ code == codes.Code(http.StatusRequestTimeout) ||
+ strings.Contains(err.Error(), "timeout") ||
+ strings.Contains(err.Error(), "deadline exceeded") {Also applies to: 634-644, 667-677 🤖 Prompt for AI Agents |
||
| } | ||
| return resp.Result, next, nil | ||
| } | ||
| return resp.Result, next, nil | ||
|
|
||
| return nil, "", fmt.Errorf("failed to get variable set links after %d retries", maxRetries) | ||
| } | ||
|
|
||
| func (c *Client) GetVariablesBySetIDs(ctx context.Context, setIDs []string, pg PaginationVars) ([]ItemOptionNew, string, error) { | ||
|
|
@@ -611,11 +626,25 @@ | |
| } | ||
| req = append(req, paginationVarsToReqOptions(&pg)...) | ||
|
|
||
| next, err := c.get(ctx, fmt.Sprintf(ItemOptionNewBaseUrl, c.deployment), &resp, req...) | ||
| if err != nil { | ||
| return nil, "", err | ||
| maxRetries := 3 | ||
| baseDelay := 2 * time.Second | ||
|
|
||
| for attempt := 0; attempt < maxRetries; attempt++ { | ||
| next, err := c.get(ctx, fmt.Sprintf(ItemOptionNewBaseUrl, c.deployment), &resp, req...) | ||
| if err != nil { | ||
| if status.Code(err) == codes.DeadlineExceeded || strings.Contains(err.Error(), "timeout") || strings.Contains(err.Error(), "deadline exceeded") { | ||
| if attempt < maxRetries-1 { | ||
| delay := baseDelay * time.Duration(1<<attempt) | ||
| time.Sleep(delay) | ||
| continue | ||
| } | ||
| } | ||
| return nil, "", err | ||
| } | ||
| return resp.Result, next, nil | ||
| } | ||
| return resp.Result, next, nil | ||
|
|
||
| return nil, "", fmt.Errorf("failed to get variables by set IDs after %d retries", maxRetries) | ||
| } | ||
|
|
||
| func (c *Client) GetChoicesForVariables(ctx context.Context, varIDs []string, pg PaginationVars) ([]QuestionChoice, string, error) { | ||
|
|
@@ -630,11 +659,25 @@ | |
| } | ||
| req = append(req, paginationVarsToReqOptions(&pg)...) | ||
|
|
||
| next, err := c.get(ctx, fmt.Sprintf(QuestionChoiceBaseUrl, c.deployment), &resp, req...) | ||
| if err != nil { | ||
| return nil, "", err | ||
| maxRetries := 3 | ||
| baseDelay := 2 * time.Second | ||
|
|
||
| for attempt := 0; attempt < maxRetries; attempt++ { | ||
| next, err := c.get(ctx, fmt.Sprintf(QuestionChoiceBaseUrl, c.deployment), &resp, req...) | ||
| if err != nil { | ||
| if status.Code(err) == codes.DeadlineExceeded || strings.Contains(err.Error(), "timeout") || strings.Contains(err.Error(), "deadline exceeded") { | ||
| if attempt < maxRetries-1 { | ||
| delay := baseDelay * time.Duration(1<<attempt) | ||
| time.Sleep(delay) | ||
| continue | ||
| } | ||
| } | ||
| return nil, "", err | ||
| } | ||
| return resp.Result, next, nil | ||
| } | ||
| return resp.Result, next, nil | ||
|
|
||
| return nil, "", fmt.Errorf("failed to get choices for variables after %d retries", maxRetries) | ||
| } | ||
|
|
||
| // Unused but consider switching to this to get both direct catalog item variables and variables from variable sets. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix gofmt/goimports formatting before merging.
CI failed because this file is not gofmt/goimports formatted. Please run
goimports -w pkg/connector/connector.go(orgofmt) and re-push so the pipeline passes.🧰 Tools
🪛 GitHub Check: go-lint
[failure] 124-124:
File is not properly formatted (goimports)
🪛 GitHub Actions: ci
[error] 124-124: golangci-lint: File is not properly formatted (goimports). Run 'goimports -w' or 'gofmt -w' to fix formatting.
🤖 Prompt for AI Agents