feat: support custom rate-limiting strategies #116
Merged
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