Commit 6df09c7d authored by Kostas Chartsias's avatar Kostas Chartsias
Browse files

async HTTP calls

parent c85751e1
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
fastmcp==2.12.5
pydantic==2.12.3
python-dotenv==1.1.1
Requests==2.32.5
httpx==0.27.2
fastapi==0.115.0
uvicorn==0.32.0
+6 −5
Original line number Diff line number Diff line
import logging
import requests
import httpx
from dotenv import load_dotenv
from pathlib import Path
import os
@@ -23,7 +23,8 @@ async def get_app_definitions() -> dict:
    url = f"{SESSION_SERVICE_URL}/apps"
    headers = {"accept": "application/json"}

    response = requests.get(url, headers=headers, allow_redirects=True)
    async with httpx.AsyncClient(trust_env=True) as client:
        response = await client.get(url, headers=headers, follow_redirects=True, timeout=10)
        response.raise_for_status()
        data = response.json()

+17 −14
Original line number Diff line number Diff line
import json
import logging
import requests
import httpx
from pathlib import Path
from MCP_module.models.qod_models import *
import os
@@ -47,9 +47,10 @@ async def create_qod_session(inp: CreateQoDSessionInput) -> QoDSessionMinimalRes
    logger.debug("Final request payload: %s", json.dumps(template, indent=2))

    try:
        response = requests.post(f"{SESSION_SERVICE_URL}/sessions", json=template, proxies=None)
        async with httpx.AsyncClient(trust_env=True) as client:
            response = await client.post(f"{SESSION_SERVICE_URL}/sessions", json=template)
            response.raise_for_status()
    except requests.RequestException as e:
    except httpx.HTTPError as e:
        logger.error("Failed to send request to session service: %s", e)
        raise

@@ -72,9 +73,10 @@ async def get_qod_session(inp: GetQoDSessionInput) -> QoDSessionFullResponse:
    logger.debug("Fetching session details from: %s", session_url)

    try:
        response = requests.get(session_url, proxies=None)
        async with httpx.AsyncClient(trust_env=True) as client:
            response = await client.get(session_url)
            response.raise_for_status()
    except requests.RequestException as e:
    except httpx.HTTPError as e:
        logger.error("Failed to get session %s: %s", inp.sessionId, e)
        raise

@@ -105,7 +107,8 @@ async def delete_qod_session(inp: GetQoDSessionInput) -> str:
    logger.debug("Deleting session at: %s", session_url)

    try:
        response = requests.delete(session_url, proxies=None)
        async with httpx.AsyncClient(trust_env=True) as client:
            response = await client.delete(session_url)
        if response.status_code == 204:
            logger.info("Session %s deleted successfully", inp.sessionId)
            return "success"
@@ -117,8 +120,9 @@ async def delete_qod_session(inp: GetQoDSessionInput) -> str:
                response.text
            )
            response.raise_for_status()
    except requests.RequestException as e:
    except httpx.HTTPError as e:
        logger.error("Failed to delete session %s: %s", inp.sessionId, e)
        raise


async def list_qod_sessions(inp: QoDSessionsList) -> List[QoDSessionListResponse]:
@@ -136,9 +140,10 @@ async def list_qod_sessions(inp: QoDSessionsList) -> List[QoDSessionListResponse
    logger.debug("Fetching QoS sessions with payload: %s", json.dumps(payload, indent=2))

    try:
        response = requests.post(sessions_url, json=payload)
        async with httpx.AsyncClient(trust_env=True) as client:
            response = await client.post(sessions_url, json=payload)
            response.raise_for_status()
    except requests.RequestException as e:
    except httpx.HTTPError as e:
        logger.error("Failed to retrieve QoS sessions: %s", e)
        raise

@@ -170,5 +175,3 @@ async def list_qod_sessions(inp: QoDSessionsList) -> List[QoDSessionListResponse
        ))

    return sessions