Improve the dahboard with the weather info 2
This commit is contained in:
4
services/external/app/api/traffic.py
vendored
4
services/external/app/api/traffic.py
vendored
@@ -55,8 +55,8 @@ async def get_current_traffic(
|
||||
# Continue processing - event publishing failure shouldn't break the API
|
||||
|
||||
logger.debug("Successfully returning traffic data",
|
||||
volume=traffic.traffic_volume,
|
||||
congestion=traffic.congestion_level)
|
||||
volume=traffic.get('traffic_volume') if isinstance(traffic, dict) else getattr(traffic, 'traffic_volume', None),
|
||||
congestion=traffic.get('congestion_level') if isinstance(traffic, dict) else getattr(traffic, 'congestion_level', None))
|
||||
return traffic
|
||||
|
||||
except HTTPException:
|
||||
|
||||
45
services/external/app/api/weather.py
vendored
45
services/external/app/api/weather.py
vendored
@@ -155,3 +155,48 @@ async def get_weather_forecast(
|
||||
except Exception as e:
|
||||
logger.error("Failed to get weather forecast", error=str(e))
|
||||
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
||||
|
||||
@router.get("/weather/status")
|
||||
async def get_weather_status():
|
||||
"""Get AEMET API status and diagnostics"""
|
||||
try:
|
||||
from app.core.config import settings
|
||||
|
||||
# Test AEMET API connectivity
|
||||
aemet_status = "unknown"
|
||||
aemet_message = "Not tested"
|
||||
|
||||
try:
|
||||
# Quick test of AEMET API
|
||||
test_weather = await weather_service.get_current_weather(40.4168, -3.7038)
|
||||
if test_weather and hasattr(test_weather, 'source') and test_weather.source == "aemet":
|
||||
aemet_status = "healthy"
|
||||
aemet_message = "AEMET API responding correctly"
|
||||
elif test_weather and hasattr(test_weather, 'source') and test_weather.source == "synthetic":
|
||||
aemet_status = "degraded"
|
||||
aemet_message = "AEMET API unavailable - using synthetic data"
|
||||
else:
|
||||
aemet_status = "degraded"
|
||||
aemet_message = "Weather service returned unexpected data format"
|
||||
except Exception as e:
|
||||
aemet_status = "unhealthy"
|
||||
aemet_message = f"AEMET API error: {str(e)}"
|
||||
|
||||
return {
|
||||
"status": "ok",
|
||||
"aemet": {
|
||||
"status": aemet_status,
|
||||
"message": aemet_message,
|
||||
"api_key_configured": bool(settings.AEMET_API_KEY),
|
||||
"enabled": getattr(settings, 'AEMET_ENABLED', True),
|
||||
"base_url": settings.AEMET_BASE_URL,
|
||||
"timeout": settings.AEMET_TIMEOUT, # Now correctly shows 60 from config
|
||||
"retry_attempts": settings.AEMET_RETRY_ATTEMPTS
|
||||
},
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
"service": "external-weather-service"
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
logger.error("Failed to get weather status", error=str(e))
|
||||
raise HTTPException(status_code=500, detail=f"Status check failed: {str(e)}")
|
||||
|
||||
Reference in New Issue
Block a user