feat(python): typed ping/get_session_state/get_worker_info/drain_events session helpers

This commit is contained in:
Joseph Doherty
2026-10-22 06:06:54 -04:00
parent 488649ce99
commit 99347d3f00
3 changed files with 114 additions and 0 deletions
@@ -838,6 +838,55 @@ class Session:
)
return reply.activate.status
async def ping(self, message: str = "", *, correlation_id: str = "") -> pb.MxCommandReply:
"""Invoke the worker `Ping` diagnostic and return its reply."""
return await self.invoke(
pb.MxCommand(kind=pb.MX_COMMAND_KIND_PING, ping=pb.PingCommand(message=message)),
correlation_id=correlation_id,
)
async def get_session_state(self, *, correlation_id: str = "") -> int:
"""Return the worker-reported `SessionState` enum value."""
reply = await self.invoke(
pb.MxCommand(
kind=pb.MX_COMMAND_KIND_GET_SESSION_STATE,
get_session_state=pb.GetSessionStateCommand(),
),
correlation_id=correlation_id,
)
return reply.session_state.state
async def get_worker_info(self, *, correlation_id: str = "") -> pb.WorkerInfoReply:
"""Return worker process id, version, and MXAccess ProgID/CLSID."""
reply = await self.invoke(
pb.MxCommand(
kind=pb.MX_COMMAND_KIND_GET_WORKER_INFO,
get_worker_info=pb.GetWorkerInfoCommand(),
),
correlation_id=correlation_id,
)
return reply.worker_info
async def drain_events(
self,
max_events: int = 0,
*,
correlation_id: str = "",
) -> list[pb.MxEvent]:
"""Drain queued worker events (diagnostic).
A reply may carry fewer than *max_events* (server count and frame-size
caps); call repeatedly until an empty list is returned.
"""
reply = await self.invoke(
pb.MxCommand(
kind=pb.MX_COMMAND_KIND_DRAIN_EVENTS,
drain_events=pb.DrainEventsCommand(max_events=max_events),
),
correlation_id=correlation_id,
)
return list(reply.drain_events.events)
def stream_events(
self,
*,