Open
Conversation
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.
设计频率限制器类,支持域名级别的请求频率统计和限制
修改 SunRequests 类,集成频率限制功能
添加设置频率限制的方法
主要改动
修改了 adata/common/utils/sunrequests.py 文件,添加了:
RateLimiter 类 - 单例模式的频率限制器,负责:
集成到 SunRequests 类 - 在 request() 方法中自动调用频率限制器
便捷的配置方法 :
使用示例
from adata.common.utils.sunrequests import set_default_rate_limit, set_domain_rate_limit
设置全局默认每分钟 50 次请求
set_default_rate_limit(50)
为特定域名设置限制
set_domain_rate_limit("api.example.com", 100)