feat: add cold debugging
Browse files44 unmodified lines4546474849505152535455565758596061626364656667686970717244 unmodified lines"checks": {}}return health_status@app.post("/v1/generateTripPlan", response_model=PlanResponse)def generate_trip_plan(request: PlanRequest):data_importer.coldStartDatabase()try:trip_plan = asyncio.run(agent.query_with_rag(request))return PlanResponse(tripOverview=trip_plan.tripOverview,query_params=request,retrieved_data=trip_plan.retrieved_data,trip_plan=trip_plan.trip_plan,preparation=trip_plan.preparation,meta={"status": "success", "timestamp": datetime.utcnow().isoformat()})except Exception as e:logger.error(f"Error in generate_trip_plan: {e}")raise HTTPException(status_code=500,detail={"error": "Internal server error","message": "Failed to generate trip plan","details": str(e)})@app.post("/v1/addYoutubeLink", response_model=YoutubeLinkResponse)44 unmodified lines4546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210344 unmodified lines"checks": {}}return health_statusMAX_RETRIES = 3RETRY_DELAY = 2 # seconds@app.post("/v1/generateTripPlan", response_model=PlanResponse)def generate_trip_plan(request: PlanRequest):data_importer.coldStartDatabase()for attempt in range(MAX_RETRIES):try:logger.info(f"Generating trip plan - attempt {attempt + 1}/{MAX_RETRIES}")trip_plan = asyncio.run(agent.query_with_rag(request))return PlanResponse(tripOverview=trip_plan.tripOverview,query_params=request,retrieved_data=trip_plan.retrieved_data,trip_plan=trip_plan.trip_plan,preparation=trip_plan.preparation,meta={"status": "success","timestamp": datetime.utcnow().isoformat(),"attempt": attempt + 1})except (asyncio.TimeoutError, Timeout, ConnectionError) as timeout_error:logger.warning(f"Timeout error on attempt {attempt + 1}: {timeout_error}")# If this was the last attempt, raise the errorif attempt == MAX_RETRIES - 1:logger.error(f"All {MAX_RETRIES} attempts failed due to timeout")raise HTTPException(status_code=504, # Gateway Timeoutdetail={"error": "Request timeout","message": f"Failed to generate trip plan after {MAX_RETRIES} attempts","details": "The service is experiencing high load. Please try again later."})# Wait before retryinglogger.info(f"Retrying in {RETRY_DELAY} seconds...")time.sleep(RETRY_DELAY)except Exception as e:# For non-timeout errors, don't retrylogger.error(f"Non-timeout error in generate_trip_plan: {e}")raise HTTPException(status_code=500,detail={"error": "Internal server error","message": "Failed to generate trip plan","details": str(e),"attempt": attempt + 1})@app.post("/v1/addYoutubeLink", response_model=YoutubeLinkResponse)
app.py+50-19