feat: support custom rate-limiting strategies#116
Merged
karashiiro merged 1 commit intothe-convocation:mainfrom Jan 19, 2025
Merged
feat: support custom rate-limiting strategies#116karashiiro merged 1 commit intothe-convocation:mainfrom
karashiiro merged 1 commit intothe-convocation:mainfrom
Conversation
Implements support for custom rate-limiting strategies, allowing for changing the default library behavior of waiting until the current period has expired. This allows for significantly more flexibility in how rate-limiting is handled. This also adds a new implementation of this strategy that simply throws an error when being rate-limited. One of the primary desired use cases for this is pooling auth to automatically rotate between users whenever one user gets rate-limited. This will require a more significant refactor of the scraper and so is not included at this time. As a workaround, library consumers can leverage `ErrorRateLimitStrategy` to throw immediately when being rate-limited, and use that to pool `Scraper` instances themselves. Given that the code has a strong assumption on only being authenticated with one user at a time, that may well be how this library implements pooling in the future (maybe a `PooledScraper` with the same public interface that internally manages multiple `Scraper` instances).
Collaborator
Author
|
Ran tests locally: |
|
Hi @karashiiro for some reason when I do the |
Collaborator
Author
|
Looks like an oversight in how the error was constructed and missed due to a bad test, will have a fix out shortly. |
Collaborator
Author
|
Fixed in v0.15.1 @pkdev08 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements support for custom rate-limiting strategies, allowing for changing the default library behavior of waiting until the current period has expired. This allows for significantly more flexibility in how rate-limiting is handled, and also enables library consumers to define their own implementations that do monitoring and/or logging when rate-limiting occurs by implementing
RateLimitStrategythemselves.This also adds a new implementation of this strategy that simply throws an error when being rate-limited:
On pooling (tl;dr not yet but now you can DIY it)
One of the primary desired use cases for this is pooling auth to automatically rotate between users whenever one user gets rate-limited. Implementing this within the
Scraperclass will require a more significant refactor of the scraper and so is not in scope at this time. As a workaround, library consumers can leverageErrorRateLimitStrategyto throw immediately when being rate-limited, and use that to poolScraperinstances themselves (pseudocode):The above pseudocode is not the only (or the cleanest) way this can be done, but (for now) the specifics are left as an exercise for library consumers.
Given that the code has a strong assumption on only being authenticated with one user at a time, that may well be how this library implements pooling in the future, to avoid the aforementioned refactor; maybe a
PooledScraperwith the same public interface that internally manages multipleScraperinstances.Resolves #81, closes #115, partially addresses #87