Skip to content

Commit ccf286f

Browse files
committed
feat: add pilotID from pilot stamp (needs PilotAgents schema)
1 parent f104b2b commit ccf286f

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from __future__ import annotations
22

33
from pydantic import BaseModel
4+
from sqlalchemy import select
5+
6+
from diracx.db.sql.pilot_agents.schema import PilotAgents
7+
from diracx.db.sql.utils import BaseSQLDB
48

59
from ..dependencies import PilotLogsDB
610
from ..fastapi_classes import DiracxRouter
@@ -30,7 +34,17 @@ async def send_message(
3034
logger.warning(f"Message received '{data}'")
3135
await check_permissions(action=ActionType.CREATE, pilot_db=pilot_logs_db)
3236

33-
pilot_id = 1234 # need to get pilot id from pilot_stamp (via pilot DB)
37+
pilot_id = 0 # need to get pilot id from pilot_stamp (via PilotAgentsDB)
38+
piloAgentsDB = BaseSQLDB.available_implementations("PilotAgentsDB")[0]
39+
url = BaseSQLDB.available_urls()["PilotAgentsDB"]
40+
db = piloAgentsDB(url)
41+
42+
async with db.engine_context():
43+
async with db:
44+
stmt = select(
45+
(PilotAgents.PilotID).where(PilotAgents.PilotStamp == data.pilot_stamp)
46+
)
47+
pilot_id = (await db.conn.execute(stmt)).scalar_one()
3448

3549
docs = []
3650
for line in data.lines:

0 commit comments

Comments
 (0)