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 c901600

Browse files
code refactored
1 parent 5920efa commit c901600

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

‎src/management_api/email/email.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Emailer:
1414
NOTE The Message Queue will send out messages every 5 minutes
1515
Emailing Class, used to create email servers and manage sending emails
1616
"""
17-
17+
# TODO create your Own SMTP server to handle emails
1818
def __init__(self):
1919
self.email_queues = Queue(maxsize=1024)
2020
self._dev_messages_queue = Queue(maxsize=100)

‎src/ratelimit/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class RateLimit:
1313
requests to less than 100 per second for each edge server in cloudflare
1414
makes sense. should leave room enough to service other regions
1515
"""
16-
def __init__(self, max_requests: int = 100, duration: int = 1):
16+
def __init__(self, max_requests: int = 1000, duration: int = 1):
1717
self.max_requests = max_requests
1818
self.duration_seconds = duration
1919
self.requests = []

‎src/requests/__init__.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ async def requester(api_url: str, timeout: int = 30):
5656
class ServerMonitor:
5757

5858
def __init__(self):
59-
self.response_time_thresh_hold: int = 900 # 900 milliseconds
59+
# 900 milliseconds
60+
self.response_time_thresh_hold: int = 900
6061
self.healthy_server_urls: list[str] = config_instance().API_SERVERS.SERVERS_LIST.split(",")
6162
# Define the health check endpoint for each server
6263
self._server_monitor_endpoint = '/_ah/warmup'
@@ -67,8 +68,7 @@ async def check_health(self, api_url: str) -> tuple[str, bool]:
6768
health_check_url = f"{api_url}{self._server_monitor_endpoint}"
6869
request_logger.info(f"Server Health Probe: {health_check_url}")
6970
try:
70-
async with httpx.AsyncClient() as client:
71-
response = await async_client.get(url=health_check_url)
71+
response = await async_client.get(url=health_check_url)
7272
if response.status_code == 200:
7373
request_logger.info(f"server still healthy : {api_url}")
7474
return api_url, True
@@ -79,29 +79,28 @@ async def check_health(self, api_url: str) -> tuple[str, bool]:
7979

8080
except (ConnectionError, TimeoutError):
8181
return api_url, False
82-
except httpx.HTTPErrorashttp_err:
82+
except httpx.HTTPError:
8383
return api_url, False
8484

8585
# Sort the healthy servers by their response time
8686
async def measure_response_time(self, api_url: str) -> tuple[str, float | None]:
8787
try:
8888
check_url: str = f"{api_url}{self._server_monitor_endpoint}"
8989
request_logger.info(f"Server Health Probe: {check_url}")
90-
async with httpx.AsyncClient() as client:
91-
start_time = time.perf_counter()
92-
response = await async_client.get(url=check_url)
93-
if response.status_code == 200:
94-
elapsed_time = int((time.perf_counter() - start_time) * 1000)
95-
request_logger.info(f"server : {api_url} latency : {elapsed_time}")
96-
return api_url, elapsed_time
97-
else:
98-
request_logger.info(f"server : {api_url} Not healthy")
99-
request_logger.info(f"Response : {response.text}")
100-
return api_url, None
90+
start_time = time.perf_counter()
91+
response = await async_client.get(url=check_url)
92+
if response.status_code == 200:
93+
elapsed_time = int((time.perf_counter() - start_time) * 1000)
94+
request_logger.info(f"server : {api_url} latency : {elapsed_time}")
95+
return api_url, elapsed_time
96+
else:
97+
request_logger.info(f"server : {api_url} Not healthy")
98+
request_logger.info(f"Response : {response.text}")
99+
return api_url, None
101100

102101
except (ConnectionError, TimeoutError):
103102
return api_url, None
104-
except httpx.HTTPErrorashttp_err:
103+
except httpx.HTTPError:
105104
return api_url, None
106105

107106
async def sort_api_servers_by_health(self) -> None:
@@ -117,4 +116,3 @@ async def sort_api_servers_by_health(self) -> None:
117116
sorted_response_times = sorted(response_time_results, key=lambda x: x[1])
118117
within_threshold = [api_url for api_url, response_time in sorted_response_times if response_time < self.response_time_thresh_hold]
119118
self.healthy_server_urls = within_threshold if within_threshold else [config_instance().API_SERVERS.SLAVE_API_SERVER]
120-

0 commit comments

Comments
(0)

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