From 4787374106ca16113a7ab200f741f4c5018f1f74 Mon Sep 17 00:00:00 2001 From: martynia Date: Mon, 30 Sep 2024 17:51:51 +0200 Subject: [PATCH] feat: add pilotID from pilot stamp (needs PilotAgents schema) --- .../routers/pilot_logging/remote_logger.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py b/diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py index 03f7f367..1c51cbfd 100644 --- a/diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py +++ b/diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py @@ -1,6 +1,10 @@ from __future__ import annotations from pydantic import BaseModel +from sqlalchemy import select + +from diracx.db.sql.pilot_agents.schema import PilotAgents +from diracx.db.sql.utils import BaseSQLDB from ..dependencies import PilotLogsDB from ..fastapi_classes import DiracxRouter @@ -30,7 +34,17 @@ async def send_message( logger.warning(f"Message received '{data}'") await check_permissions(action=ActionType.CREATE, pilot_db=pilot_logs_db) - pilot_id = 1234 # need to get pilot id from pilot_stamp (via pilot DB) + pilot_id = 0 # need to get pilot id from pilot_stamp (via PilotAgentsDB) + piloAgentsDB = BaseSQLDB.available_implementations("PilotAgentsDB")[0] + url = BaseSQLDB.available_urls()["PilotAgentsDB"] + db = piloAgentsDB(url) + + async with db.engine_context(): + async with db: + stmt = select( + (PilotAgents.PilotID).where(PilotAgents.PilotStamp == data.pilot_stamp) + ) + pilot_id = (await db.conn.execute(stmt)).scalar_one() docs = [] for line in data.lines: