feat: Implement dynamic timeout control for NASA API requests from system_settings

main
mula.liu 2025-12-03 18:33:08 +08:00
parent 5172ec5d66
commit a5f18747b2
5 changed files with 8 additions and 4 deletions

View File

@ -58,7 +58,8 @@ async def create_celestial_body(
@router.get("/search")
async def search_celestial_body(
name: str = Query(..., description="Body name or ID to search in NASA Horizons")
name: str = Query(..., description="Body name or ID to search in NASA Horizons"),
db: AsyncSession = Depends(get_db)
):
"""
Search for a celestial body in NASA Horizons database by name or ID
@ -68,7 +69,7 @@ async def search_celestial_body(
logger.info(f"Searching for celestial body: {name}")
try:
result = await horizons_service.search_body_by_name(name)
result = await horizons_service.search_body_by_name(name, db)
if result["success"]:
logger.info(f"Found body: {result['full_name']}")
@ -111,7 +112,7 @@ async def get_celestial_nasa_data(
try:
# Fetch raw text from Horizons using the body_id
# Note: body.id corresponds to JPL Horizons ID
raw_text = await horizons_service.get_object_data_raw(body.id)
raw_text = await horizons_service.get_object_data_raw(body.id, db)
return {"id": body.id, "name": body.name, "raw_data": raw_text}
except Exception as e:
logger.error(f"Failed to fetch raw data for {body_id}: {e}")

View File

@ -342,7 +342,7 @@ async def get_celestial_positions(
else:
# Download from NASA Horizons
pos_data = await horizons_service.get_body_positions(body.id, start_dt, end_dt, step)
pos_data = await horizons_service.get_body_positions(body.id, db, start_dt, end_dt, step)
positions_list = [
{"time": p.time.isoformat(), "x": p.x, "y": p.y, "z": p.z}
for p in pos_data

View File

@ -219,6 +219,7 @@ async def download_positions(
# Download from NASA Horizons
positions = await horizons_service.get_body_positions(
body_id=body_id,
db=db,
start_time=target_date,
end_time=target_date,
step="1d"

View File

@ -62,6 +62,7 @@ async def download_positions_task(task_id: int, body_ids: List[str], dates: List
# Download
positions = await horizons_service.get_body_positions(
body_id=body_id,
db=db,
start_time=target_date,
end_time=target_date,
step="1d"

View File

@ -152,6 +152,7 @@ class OrbitService:
# Get positions from Horizons (synchronous call)
positions = await horizons_service.get_body_positions(
body_id=body_id,
db=session,
start_time=start_time,
end_time=end_time,
step=f"{step_days}d"