Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e010dff

Browse files
code refactored
1 parent d25e40e commit e010dff

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

‎src/authorize/authorize.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from src.utils.my_logger import init_logger
1414

1515
lock = asyncio.Lock()
16-
# TODO convert api_keys_lookup to a function that looksup api_keys from a redis cache
16+
1717
api_keys_lookup = api_keys.get
1818
cache_api_keys_func = cache_api_keys
1919

@@ -160,7 +160,7 @@ async def take_credit_method(api_key: str, path: str):
160160

161161
with next(sessions) as session:
162162
# TO Update subscription Model
163-
# TODO create a queue and put this in
163+
# TODO create a queue and put this in will make sense as demand for services increases
164164
await Subscriptions.update_subscription(subscription_data=subscription_dict, session=session)
165165

166166

@@ -188,7 +188,15 @@ async def return_kwargs(kwargs):
188188
return api_key, path
189189

190190
async def rate_limiter(api_key):
191-
"""this method applies the actual rate_limiter"""
191+
"""
192+
**rate_limiter**
193+
this only rate limits clients by api keys,
194+
there is also a regional rate limiter and a global rate limit both created so that the gateway
195+
does not end up taking too much traffic and is able to recover from DDOS attacks easily.
196+
197+
--> the rate_limiter has a side effect of also authorizing the client based on API Keys
198+
199+
this method applies the actual rate_limiter per client basis"""
192200
# Rate Limiting Section
193201
async with apikeys_lock:
194202
api_keys_model_dict: dict[str, str | int] = api_keys_lookup(api_key)
@@ -200,7 +208,6 @@ async def rate_limiter(api_key):
200208
if now - last_request_timestamp > duration:
201209
api_keys_model_dict['requests_count'] = 0
202210
if api_keys_model_dict['requests_count'] >= limit:
203-
# TODO consider returning a JSON String with data on the rate rate_limit and how long to wait
204211
time_left = last_request_timestamp + duration - now
205212
mess: str = f"EOD Stock API - Rate Limit Exceeded. Please wait {time_left:.0f} seconds before making " \
206213
f"another request, or upgrade your plan to better take advantage of extra resources " \

‎src/authorize/resources.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,3 @@ async def get_resource_name(path: str) -> str:
138138
"sentiment_analysis.tweeter.stock_code": 3, # x result size
139139
"social.trend_setters.stock_code": 3, # X result size,
140140
}
141-
142-
# TODO need to create a passive method which will automatically substract the credit
143-
# from plan limit
144-
145-
if __name__ == "__main__":
146-
print(path_to_resource())

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /