diff --git a/src/aeros_simulation/service.py b/src/aeros_simulation/service.py index f5c8c6c..918a26a 100644 --- a/src/aeros_simulation/service.py +++ b/src/aeros_simulation/service.py @@ -35,6 +35,20 @@ from .utils import calculate_eaf, stream_large_array # client = httpx.AsyncClient(timeout=300.0) # Managed in src.aeros_utils active_simulations = {} +async def call_ahm_callback_service(simulation_id: str, job_id: str): + from src.config import AHM_BASE_URL, AHM_SIMULATION_CALLBACK_URL + url = f"{AHM_BASE_URL}{AHM_SIMULATION_CALLBACK_URL}" + payload = { + "simulation_id": simulation_id, + "job_id": job_id, + "status": "completed" + } + + async with httpx.AsyncClient() as client: + resp = await client.post(url, json=payload, timeout=10.0) + resp.raise_for_status() + return True + # Get Data Service async def get_all(common, current_user): @@ -439,8 +453,6 @@ async def execute_simulation(*, db_session: DbSession, simulation_id: Optional[U ) file_obj = response.raw - - await save_simulation_result( db_session=db_session, simulation_id=simulation.id, schematic_name=sim_data["SchematicName"], eq_update=eq_update, file_path=file_obj ) diff --git a/src/config.py b/src/config.py index 77cfef0..6bb946d 100644 --- a/src/config.py +++ b/src/config.py @@ -106,4 +106,7 @@ ROLE_ID=config('ROLE_ID', default=None) SECRET_ID=config('SECRET_ID', default=None) AEROS_SECRET_PATH=config('AEROS_SECRET_PATH', default=None) -USE_LICENSE_APP = config("USE_LICENSE_APP", cast=bool, default=True) \ No newline at end of file +USE_LICENSE_APP = config("USE_LICENSE_APP", cast=bool, default=True) + +AHM_BASE_URL = config("AHM_BASE_URL", default="http://192.168.1.82:8000/ahm") +AHM_SIMULATION_CALLBACK_URL = config("AHM_SIMULATION_CALLBACK_URL", default="/api/v1/simulations/rbd/callback") \ No newline at end of file diff --git a/temporal/activity.py b/temporal/activity.py index d692901..6cb36e8 100644 --- a/temporal/activity.py +++ b/temporal/activity.py @@ -1,11 +1,8 @@ import asyncio -import requests from temporalio import activity import os import redis.asyncio as redis -AHM_BASE_URL = os.getenv("AHM_BASE_URL", "http://192.168.1.82:8000/ahm") -AHM_SIMULATION_CALLBACK_URL = os.getenv("AHM_SIMULATION_CALLBACK_URL", "/api/v1/simulations/rbd/callback") REDIS_HOST = os.getenv("REDIS_HOST", "192.168.1.82") REDIS_PORT = int(os.getenv("REDIS_PORT", 6379)) @@ -94,19 +91,13 @@ async def update_contribution_bulk_mappings_activity(sim_id: str): @activity.defn async def call_callback_ahm(params): + from src.aeros_simulation.service import call_ahm_callback_service sim_id = params["simulation_id"] job_id = params["job_id"] - url = f"{AHM_BASE_URL}{AHM_SIMULATION_CALLBACK_URL}" - payload = { - "simulation_id": sim_id, - "job_id": job_id, - "status" : "completed" - } - try: - callback_response = requests.post(url, json=payload, timeout=5) - callback_response.raise_for_status() + await call_ahm_callback_service(sim_id, job_id) + return True except Exception as e: raise e