Skip to content

Commit

Permalink
feat: add get_logs operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
martynia committed Nov 21, 2024
1 parent 85da2cc commit 1c22760
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions diracx-db/src/diracx/db/os/pilot_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class PilotLogsDB(BaseOSDB):
fields = {
"PilotStamp": {"type": "keyword"},
"PilotID": {"type": "long"},
"LineNumber": {"type": "long"},
"Message": {"type": "text"},
"VO": {"type": "keyword"},
Expand Down
20 changes: 19 additions & 1 deletion diracx-routers/src/diracx/routers/pilot_logging/remote_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,28 @@ async def send_message(
docs.append(
{
"PilotStamp": data.pilot_stamp,
"PilotID": pilot_id,
"VO": data.vo,
"LineNumber": line.line_no,
"Message": line.line,
}
)
await pilot_logs_db.bulk_insert(pilot_logs_db.index_name(pilot_id), docs)
return data
return pilot_id


@router.get("/logs")
async def get_logs(
pilot_id: int,
db: PilotLogsDB,
check_permissions: CheckPilotLogsPolicyCallable,
):
logger.warning(f"Retrieving message for pilot ID '{pilot_id}'")
await check_permissions(action=ActionType.QUERY, pilot_db=db)

result = await db.search(
["Message"],
[{"parameter": "PilotID", "operator": "eq"} | {"value": pilot_id}],
[{"parameter": "LineNumber", "direction": "asc"}],
)
return result

0 comments on commit 1c22760

Please sign in to comment.