Coder Social home page Coder Social logo

go-github-ratelimit's People

Contributors

gofri avatar kazhuravlev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

go-github-ratelimit's Issues

Handle Callback without waiting/reattempting?

I'll preface this with saying my use case here might be a little niche.

I'm using go-github-ratelimit in a Kubernetes controller where I have a pool of go-github clients allocated. Because of the nature of the controller, it's not feasible to wait/block for significant periods of time. Instead, it's preferable for the controller to requeue and reattempt later.

I've defined a callback function that cordons off the affect client until the wait period is over, and allows the HTTP request to fail/return an error. At which point, the controller will requeue and reattempt with a different client. However, go-github-ratelimit is still waiting outside of the callback function, and reattempting the request.

Basically what I'm wondering is, is it possible to use go-github-ratelimit to catch the Secondary rate limit error, execute some callback function, and then allow the request to fail, without waiting?

My current alternative is to manually check the response from go-github for a secondary rate limit error and do the necessary steps there, but being able to do this in a package would be nice ๐Ÿ™‚

Callback function doesn't trigger after secondary rate limit is hit

Hi,

I have some code that intiializes a go-github client using go-github-ratelimiter, with a custom callback function defined like so:

rateLimiter, err := github_ratelimit.NewRateLimitWaiterClient(tc.Transport, github_ratelimit.WithLimitDetectedCallback(func(cbContext *github_ratelimit.CallbackContext) {
		ctx := *cbContext.UserContext
		// Some other steps
}))
client := github.NewClient(rateLimiter)

But despite using a GitHub token that is secondary rate limited (for content creation), I don't ever see the callback function run.

I'm using github.com/gofri/go-github-ratelimit v1.0.2 and github.com/google/go-github/v41 v41.0.0

Add support for primary rate limits

Unlike secondary rate limits, primary rate limits are long and categorized.
As a result, sleeping is not obviously the natural response for them, and the implementation must be aware of the categories.

Options (not mutually exclusive):

  • Add a callback for when a primary rate limit is detected (no need for category awareness).
  • Handle the different categories and implement a complete solution (maybe with more freedom regarding the user's response).
  • Provide it as a separate RoundTripper.
  • Provide wrapper functions to stack them.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.