|
|
|
|
@ -4,7 +4,8 @@ from temporalio.client import Client
|
|
|
|
|
from fastapi import APIRouter, HTTPException, status
|
|
|
|
|
from fastapi.params import Query
|
|
|
|
|
|
|
|
|
|
from src.config import TEMPORAL_URL
|
|
|
|
|
from src.calculation_target_reliability.utils import wait_for_workflow
|
|
|
|
|
from src.config import TEMPORAL_URL, TR_RBD_ID
|
|
|
|
|
from src.database.core import DbSession, CollectorDbSession
|
|
|
|
|
from src.auth.service import Token
|
|
|
|
|
from src.models import StandardResponse
|
|
|
|
|
@ -55,36 +56,19 @@ async def get_target_reliability(
|
|
|
|
|
# oh_duration=duration
|
|
|
|
|
# )
|
|
|
|
|
|
|
|
|
|
if not simulation_id or duration == 17520:
|
|
|
|
|
simulation_id = "f04f365e-25d8-4036-87c2-ba1bfe1f9229"
|
|
|
|
|
if not simulation_id:
|
|
|
|
|
if duration == 17520:
|
|
|
|
|
simulation_id = TR_RBD_ID
|
|
|
|
|
else:
|
|
|
|
|
simulation = await run_rbd_simulation(
|
|
|
|
|
sim_hours=duration,
|
|
|
|
|
token=token
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
simulation_id = simulation.get("data")
|
|
|
|
|
await wait_for_workflow(simulation_id=simulation_id.get("data"))
|
|
|
|
|
else:
|
|
|
|
|
temporal_client = await Client.connect(TEMPORAL_URL)
|
|
|
|
|
|
|
|
|
|
simulation_id = await run_rbd_simulation(
|
|
|
|
|
sim_hours=duration,
|
|
|
|
|
token=token
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
workflow_id = f"simulation-{simulation_id}"
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
try:
|
|
|
|
|
handle = temporal_client.get_workflow_handle(workflow_id=workflow_id)
|
|
|
|
|
desc = await handle.describe()
|
|
|
|
|
status = desc.status.name
|
|
|
|
|
|
|
|
|
|
if status not in ["RUNNING", "CONTINUED_AS_NEW"]:
|
|
|
|
|
print(f"Workflow {workflow_id} finished with status: {status}")
|
|
|
|
|
return status
|
|
|
|
|
|
|
|
|
|
print(f"Workflow {workflow_id} still {status}, checking again in {30} seconds...")
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"Workflow {workflow_id} not found, treating as done.")
|
|
|
|
|
return "NOT_FOUND"
|
|
|
|
|
|
|
|
|
|
await asyncio.sleep(30)
|
|
|
|
|
|
|
|
|
|
await wait_for_workflow(simulation_id=simulation_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
results = await get_simulation_results(
|
|
|
|
|
|