feat: centralize AHM callback logic into service layer and update configuration management

main
Cizz22 3 months ago
parent 8987bb1874
commit 6dd40d8cb0

@ -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
)

@ -107,3 +107,6 @@ 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)
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")

@ -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

Loading…
Cancel
Save