Skip to content
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

Make Retrys by Default for NewFromToken() #632

Merged
merged 5 commits into from
Aug 28, 2023
Merged

Make Retrys by Default for NewFromToken() #632

merged 5 commits into from
Aug 28, 2023

Conversation

danaelhe
Copy link
Member

@danaelhe danaelhe commented Aug 24, 2023

Configures a retryable client with default behavior when a godo client is initialized via NewFromToken(). Also refactored the code a bit to eliminate code duplication.

If you'd like to test:

func main() {
    ctx := context.Background()
    token := "do_token_here"

    client := godo.NewFromToken(token)

    for i := 0; i < 290; i++ {
        println(i)
        _, resp, _ := client.Account.Get(ctx)
        println(resp.StatusCode)
    }
}

will yield:

2023/08/23 23:43:59 [DEBUG] GET https://api.digitalocean.com/v2/account
117
2023/08/23 23:43:59 [DEBUG] GET https://api.digitalocean.com/v2/account
2023/08/23 23:43:59 [DEBUG] GET https://api.digitalocean.com/v2/account (status: 429): retrying in 7s (4 left)

Same behavior is seen for initializing a client via godo.NewClient()

@danaelhe danaelhe requested a review from a team August 24, 2023 14:13
godo.go Outdated Show resolved Hide resolved
godo.go Outdated Show resolved Hide resolved
Copy link
Member

@andrewsomething andrewsomething left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

@danaelhe danaelhe merged commit 0161e07 into main Aug 28, 2023
7 checks passed
@danaelhe danaelhe deleted the retry_default branch August 28, 2023 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants