feat: migrate coordinator-api routers and exchange_island CLI to use centralized aitbc package HTTP client
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 9s
CLI Tests / test-cli (push) Failing after 3s
Integration Tests / test-service-integration (push) Successful in 42s
Python Tests / test-python (push) Failing after 39s
Security Scanning / security-scan (push) Successful in 2m36s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 3s
Blockchain Synchronization Verification / sync-verification (push) Failing after 2s
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 9s
CLI Tests / test-cli (push) Failing after 3s
Integration Tests / test-service-integration (push) Successful in 42s
Python Tests / test-python (push) Failing after 39s
Security Scanning / security-scan (push) Successful in 2m36s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 3s
Blockchain Synchronization Verification / sync-verification (push) Failing after 2s
- Replace httpx.Client with aitbc.AITBCHTTPClient in client.py get_blocks endpoint - Migrate monitoring_dashboard.py from httpx.AsyncClient to AITBCHTTPClient - Replace httpx with AITBCHTTPClient in blockchain.py get_balance function - Add NetworkError exception handling across all migrated endpoints - Remove async context managers in favor of direct AITBCHTTPClient usage - Remove httpx imports
This commit is contained in:
@@ -226,22 +226,27 @@ async def get_blocks(
|
||||
) -> dict: # type: ignore[arg-type]
|
||||
"""Get recent blockchain blocks"""
|
||||
try:
|
||||
import httpx
|
||||
|
||||
# Query the local blockchain node for blocks
|
||||
with httpx.Client() as client:
|
||||
response = client.get(
|
||||
"http://10.1.223.93:8082/rpc/blocks-range", params={"start": offset, "end": offset + limit}, timeout=5
|
||||
client = AITBCHTTPClient(timeout=5.0)
|
||||
try:
|
||||
blocks_data = client.get(
|
||||
"http://10.1.223.93:8082/rpc/blocks-range", params={"start": offset, "end": offset + limit}
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
blocks_data = response.json()
|
||||
return {
|
||||
"blocks": blocks_data.get("blocks", []),
|
||||
"total": blocks_data.get("total", 0),
|
||||
"limit": limit,
|
||||
"offset": offset,
|
||||
}
|
||||
return {
|
||||
"blocks": blocks_data.get("blocks", []),
|
||||
"total": blocks_data.get("total", 0),
|
||||
"limit": limit,
|
||||
"offset": offset,
|
||||
}
|
||||
except NetworkError as e:
|
||||
logger.error(f"Failed to fetch blocks: {e}")
|
||||
return {
|
||||
"blocks": [],
|
||||
"total": 0,
|
||||
"limit": limit,
|
||||
"offset": offset,
|
||||
"error": "Failed to fetch blocks",
|
||||
}
|
||||
else:
|
||||
# Fallback to empty response if blockchain node is unavailable
|
||||
return {
|
||||
|
||||
@@ -191,24 +191,25 @@ async def collect_all_health_data() -> dict[str, Any]:
|
||||
"""Collect health data from all enhanced services"""
|
||||
health_data = {}
|
||||
|
||||
async with httpx.AsyncClient(timeout=5.0) as client:
|
||||
tasks = []
|
||||
client = AITBCHTTPClient(timeout=5.0)
|
||||
tasks = []
|
||||
|
||||
for service_id, service_info in SERVICES.items():
|
||||
task = check_service_health(client, service_id, service_info)
|
||||
tasks.append(task)
|
||||
for service_id, service_info in SERVICES.items():
|
||||
task = check_service_health(client, service_id, service_info)
|
||||
tasks.append(task)
|
||||
|
||||
results = await asyncio.gather(*tasks, return_exceptions=True)
|
||||
results = await asyncio.gather(*tasks, return_exceptions=True)
|
||||
|
||||
for i, (service_id, service_info) in enumerate(SERVICES.items()):
|
||||
result = results[i]
|
||||
if isinstance(result, Exception):
|
||||
health_data[service_id] = {
|
||||
"status": "unhealthy",
|
||||
"error": str(result),
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
}
|
||||
else:
|
||||
for i, (service_id, service_info) in enumerate(SERVICES.items()):
|
||||
result = results[i]
|
||||
if isinstance(result, Exception):
|
||||
health_data[service_id] = {
|
||||
"status": "unhealthy",
|
||||
"error": str(result),
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
}
|
||||
else:
|
||||
health_data[service_id] = result
|
||||
|
||||
return health_data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user