Skip to content

Commit

Permalink
Fix jira_user table to retry rate limit exceeded errors closes #68
Browse files Browse the repository at this point in the history
  • Loading branch information
misraved committed Nov 21, 2022
1 parent 9d13e09 commit c91e0c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 18 additions & 1 deletion jira/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package jira

import "strings"
import (
"context"
"log"
"strings"

"github.com/turbot/steampipe-plugin-sdk/v4/plugin"
)

func isNotFoundError(err error) bool {
return strings.Contains(err.Error(), "404")
Expand All @@ -9,3 +15,14 @@ func isNotFoundError(err error) bool {
func isBadRequestError(err error) bool {
return strings.Contains(err.Error(), "400")
}

func shouldRetryError(retryErrors []string) plugin.ErrorPredicateWithContext {
return func(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData, err error) bool {

if strings.Contains(err.Error(), "429") {
log.Printf("[WARN] Received Rate Limit Error")
return true
}
return false
}
}
4 changes: 3 additions & 1 deletion jira/table_jira_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func tableUser(_ context.Context) *plugin.Table {
// Limit concurrency to avoid a 429 too many requests error
Func: getUserGroups,
MaxConcurrency: 50,
RetryConfig: &plugin.RetryConfig{ ShouldRetryErrorFunc: shouldRetryError([]string{"429"})},
},
},
Columns: []*plugin.Column{
Expand Down Expand Up @@ -155,12 +156,13 @@ func getUserGroups(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateDa
}

groups, _, err := client.User.GetGroups(user.AccountID)

if err != nil {
plugin.Logger(ctx).Error("jira_user.getUserGroups", "api_error", err)
return nil, err
}

return groups, nil
return groups, nil
}

//// TRANSFORM FUNCTION
Expand Down

0 comments on commit c91e0c9

Please sign in to comment.