Skip to content

Commit 6217509

Browse files
committed
feat: add get_logs operation.
1 parent 72a84ee commit 6217509

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

diracx-db/src/diracx/db/os/pilot_logs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
class PilotLogsDB(BaseOSDB):
77
fields = {
88
"PilotStamp": {"type": "keyword"},
9+
"PilotID": {"type": "long"},
910
"LineNumber": {"type": "long"},
1011
"Message": {"type": "text"},
1112
"VO": {"type": "keyword"},

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,28 @@ async def send_message(
5151
docs.append(
5252
{
5353
"PilotStamp": data.pilot_stamp,
54+
"PilotID": pilot_id,
5455
"VO": data.vo,
5556
"LineNumber": line.line_no,
5657
"Message": line.line,
5758
}
5859
)
5960
await pilot_logs_db.bulk_insert(pilot_logs_db.index_name(pilot_id), docs)
60-
return data
61+
return pilot_id
62+
63+
64+
@router.get("/logs")
65+
async def get_logs(
66+
pilot_id: int,
67+
db: PilotLogsDB,
68+
check_permissions: CheckPilotLogsPolicyCallable,
69+
):
70+
logger.warning(f"Retrieving message for pilot ID '{pilot_id}'")
71+
await check_permissions(action=ActionType.QUERY, pilot_db=db)
72+
73+
result = await db.search(
74+
["Message"],
75+
[{"parameter": "PilotID", "operator": "eq"} | {"value": pilot_id}],
76+
[{"parameter": "LineNumber", "direction": "asc"}],
77+
)
78+
return result

0 commit comments

Comments
 (0)