From 7f9572364eb22684c44be13105bca1c2b0f1be45 Mon Sep 17 00:00:00 2001 From: zehe <zehe@informatik.uni-wuerzburg.de> Date: Fri, 21 Mar 2025 13:01:43 +0100 Subject: [PATCH] cleanup --- app/api-balancer.py | 64 --------------------------------------------- 1 file changed, 64 deletions(-) diff --git a/app/api-balancer.py b/app/api-balancer.py index f8c10af..6035997 100644 --- a/app/api-balancer.py +++ b/app/api-balancer.py @@ -165,70 +165,6 @@ async def startup_event(): asyncio.create_task(update_api_pods()) -class Document(BaseModel): - text: str - - -""" -@app.post("/kallimachosPipeline") -async def process_document(request: Request): - logger.info(f"Received request") - # Read the body as raw bytes - raw_body = await request.body() - - # First, try to parse as JSON. - try: - body = json.loads(raw_body) - except json.JSONDecodeError: - # If JSON decoding fails, try to parse as URL-encoded data. - qs = raw_body.decode("utf-8") - parsed_qs = urllib.parse.parse_qs(qs) - # parse_qs returns a dict with list values; extract the first item. - body = {k: v[0] for k, v in parsed_qs.items() if v} - - text = body.get("text") - if not text: - return {"error": "Missing 'text' in request body."} - - # Wait until one pod is available. - pod_ip, pod_name = await get_free_pod() - logger.info(f"Selected pod: {pod_ip, pod_name}") - await asyncio.sleep(10) - try: - # Prepare the file to send to the API pod. - # We assume the API pod is listening on port 80. - url = f"http://{pod_ip}:80/kallimachosPipeline" - - myobj = {'text': text} - headers = {'Content-type': 'application/json; charset=utf-8'} - - async with httpx.AsyncClient(timeout=None) as client: - response = await client.post(url, data=myobj, headers=headers) - - if response.status_code != 200: - raise HTTPException( - status_code=response.status_code, - detail=f"Error from upstream API pod: {response.text}" - ) - - # Optionally, pass through relevant headers (adjust as needed) - headers = { - key: value - for key, value in response.headers.items() - if key.lower() in ["content-type", "content-disposition"] - } - return Response( - content=response.content, - status_code=response.status_code, - headers=headers - ) - except Exception as err: - raise HTTPException(status_code=500, detail=str(err)) - finally: - await mark_pod_free(pod_ip, pod_name) -""" - - @app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"]) async def proxy(path: str, request: Request): logger = app.logger if hasattr(app, "logger") else print -- GitLab