-
Notifications
You must be signed in to change notification settings - Fork 247
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
Implement rate limiting #1
Comments
Technically, this involves rate-limiting based on "resource families": https://dev.twitter.com/docs/api/1.1/get/application/rate_limit_status |
I do graceful rate-limiting like this: func TryUntilSucceeded(method func() (interface{}, error)) (result interface{}, err error) {
for {
result, err = method()
if apiErr, ok := err.(*anaconda.ApiError); ok {
limited, freed := apiErr.RateLimitCheck()
if !limited {
break
} else {
freed = freed.Add(5 * time.Second) // extra margin
now := time.Now()
fmt.Println("[rate limited] will wake up at", freed, "in", freed.Sub(now).Seconds(), "seconds")
time.Sleep(freed.Sub(now))
continue
}
} else {
break
}
}
return result, err
} and usage looks like this: users, err := TryUntilSucceeded(func() (interface {}, error) {
return lookuper.Api.GetUsersLookupByIds(chunk, nil)
})
// users.([]anaconda.TwitterUser) to get profiles I need #12 and ApiError to make this happen, but it works great. It also doesn't need |
Looks like we forgot to close this issue out before. Thanks @bobrik - the (optional) rate-limiting thats' now built-in is very similar to what you outline here. |
It should be straightforward to implement rate-limiting as https://github.com/ChimeraCoder/goangel does without changing the interface of the library.
The text was updated successfully, but these errors were encountered: