Riy777 commited on
Commit
2eac7ea
·
1 Parent(s): b03be3d

Update whale_monitor/rpc_manager.py

Browse files
Files changed (1) hide show
  1. whale_monitor/rpc_manager.py +5 -9
whale_monitor/rpc_manager.py CHANGED
@@ -18,10 +18,8 @@ RPC_HEALTH_CHECK_WINDOW = 10 # تتبع آخر 10 طلبات
18
  RPC_ERROR_THRESHOLD = 3 # عدد الأخطاء المتتالية لإيقاف مؤقت
19
  RPC_CIRCUIT_BREAKER_DURATION = 300 # 5 دقائق إيقاف مؤقت
20
 
21
- # 🔴 --- START OF CHANGE --- 🔴
22
  # (إضافة ثابت لفرض تأخير بين طلبات CoinGecko)
23
  COINGECKO_REQUEST_DELAY = 2.0 # 2.0 ثانية (يساوي 30 طلب/دقيقة كحد أقصى)
24
- # 🔴 --- END OF CHANGE --- 🔴
25
 
26
  class AdaptiveRpcManager:
27
  """
@@ -36,10 +34,8 @@ class AdaptiveRpcManager:
36
  self.rpc_semaphore = asyncio.Semaphore(5) # حد عام لـ RPC
37
  self.coingecko_semaphore = asyncio.Semaphore(1) # حد خاص لـ CoinGecko
38
 
39
- # 🔴 --- START OF CHANGE --- 🔴
40
  # (متغير لتتبع وقت آخر طلب لـ CoinGecko)
41
  self.last_coingecko_call = 0.0
42
- # 🔴 --- END OF CHANGE --- 🔴
43
 
44
  # تهيئة إعدادات الشبكة ونقاط RPC
45
  self.network_configs = self._initialize_network_configs(DEFAULT_NETWORK_CONFIGS)
@@ -160,7 +156,11 @@ class AdaptiveRpcManager:
160
  health['consecutive_errors'] += 1
161
  health['total_errors'] += 1
162
  health['last_error_time'] = time.time()
163
- if health['consecutive_errors'] >= RPC_CIRCUIT_BREAKER_THRESHOLD:
 
 
 
 
164
  health['circuit_open'] = True
165
  print(f"🚨 [RPC Manager] قاطع الدائرة مفعل! إيقاف مؤقت لـ: {endpoint.split('//')[-1]}")
166
 
@@ -214,7 +214,6 @@ class AdaptiveRpcManager:
214
  try:
215
  async with semaphore:
216
 
217
- # 🔴 --- START OF CHANGE --- 🔴
218
  # (تطبيق "الخنق" لـ CoinGecko)
219
  if use_coingecko_semaphore:
220
  current_time = time.time()
@@ -227,12 +226,10 @@ class AdaptiveRpcManager:
227
 
228
  # (تحديث وقت آخر استدعاء *قبل* الطلب)
229
  self.last_coingecko_call = time.time()
230
- # 🔴 --- END OF CHANGE --- 🔴
231
 
232
  response = await self.http_client.get(base_url, params=params, headers=headers, timeout=timeout)
233
 
234
  if response.status_code == 429: # Too Many Requests
235
- # 🔴 --- START OF CHANGE --- 🔴
236
  # (زيادة وقت الانتظار)
237
  wait_duration = 15.0
238
  print(f"⚠️ [GET] خطأ 429 (Rate Limit) من {base_url}. الانتظار {wait_duration} ثوان...")
@@ -241,7 +238,6 @@ class AdaptiveRpcManager:
241
  # (تحديث وقت آخر استدعاء مرة أخرى بعد الانتظار)
242
  if use_coingecko_semaphore:
243
  self.last_coingecko_call = time.time()
244
- # 🔴 --- END OF CHANGE --- 🔴
245
 
246
  # إعادة المحاولة مرة واحدة
247
  response = await self.http_client.get(base_url, params=params, headers=headers, timeout=timeout)
 
18
  RPC_ERROR_THRESHOLD = 3 # عدد الأخطاء المتتالية لإيقاف مؤقت
19
  RPC_CIRCUIT_BREAKER_DURATION = 300 # 5 دقائق إيقاف مؤقت
20
 
 
21
  # (إضافة ثابت لفرض تأخير بين طلبات CoinGecko)
22
  COINGECKO_REQUEST_DELAY = 2.0 # 2.0 ثانية (يساوي 30 طلب/دقيقة كحد أقصى)
 
23
 
24
  class AdaptiveRpcManager:
25
  """
 
34
  self.rpc_semaphore = asyncio.Semaphore(5) # حد عام لـ RPC
35
  self.coingecko_semaphore = asyncio.Semaphore(1) # حد خاص لـ CoinGecko
36
 
 
37
  # (متغير لتتبع وقت آخر طلب لـ CoinGecko)
38
  self.last_coingecko_call = 0.0
 
39
 
40
  # تهيئة إعدادات الشبكة ونقاط RPC
41
  self.network_configs = self._initialize_network_configs(DEFAULT_NETWORK_CONFIGS)
 
156
  health['consecutive_errors'] += 1
157
  health['total_errors'] += 1
158
  health['last_error_time'] = time.time()
159
+
160
+ # 🔴 --- START OF CHANGE --- 🔴
161
+ # (تصحيح الخطأ الطباعي: استخدام RPC_ERROR_THRESHOLD)
162
+ if health['consecutive_errors'] >= RPC_ERROR_THRESHOLD:
163
+ # 🔴 --- END OF CHANGE --- 🔴
164
  health['circuit_open'] = True
165
  print(f"🚨 [RPC Manager] قاطع الدائرة مفعل! إيقاف مؤقت لـ: {endpoint.split('//')[-1]}")
166
 
 
214
  try:
215
  async with semaphore:
216
 
 
217
  # (تطبيق "الخنق" لـ CoinGecko)
218
  if use_coingecko_semaphore:
219
  current_time = time.time()
 
226
 
227
  # (تحديث وقت آخر استدعاء *قبل* الطلب)
228
  self.last_coingecko_call = time.time()
 
229
 
230
  response = await self.http_client.get(base_url, params=params, headers=headers, timeout=timeout)
231
 
232
  if response.status_code == 429: # Too Many Requests
 
233
  # (زيادة وقت الانتظار)
234
  wait_duration = 15.0
235
  print(f"⚠️ [GET] خطأ 429 (Rate Limit) من {base_url}. الانتظار {wait_duration} ثوان...")
 
238
  # (تحديث وقت آخر استدعاء مرة أخرى بعد الانتظار)
239
  if use_coingecko_semaphore:
240
  self.last_coingecko_call = time.time()
 
241
 
242
  # إعادة المحاولة مرة واحدة
243
  response = await self.http_client.get(base_url, params=params, headers=headers, timeout=timeout)