fix(rust-client): async CA file read; typed ping/session-state/worker-info/drain-events
This commit is contained in:
@@ -17,14 +17,15 @@ use crate::generated::mxaccess_gateway::v1::mx_command_reply;
|
||||
use crate::generated::mxaccess_gateway::v1::{
|
||||
ActivateCommand, AddBufferedItemCommand, AddItem2Command, AddItemBulkCommand, AddItemCommand,
|
||||
AdviseCommand, AdviseItemBulkCommand, AdviseSupervisoryCommand, ArchestrAUserToIdCommand,
|
||||
AuthenticateUserCommand, BulkReadResult, BulkWriteResult, CloseSessionRequest, MxCommand,
|
||||
MxCommandKind, MxCommandReply, MxCommandRequest, MxDataType, MxSparseArray, MxSparseElement,
|
||||
MxValue as ProtoMxValue, OpenSessionRequest, ReadBulkCommand, RegisterCommand,
|
||||
RemoveItemBulkCommand, RemoveItemCommand, SetBufferedUpdateIntervalCommand,
|
||||
AuthenticateUserCommand, BulkReadResult, BulkWriteResult, CloseSessionRequest,
|
||||
DrainEventsCommand, GetSessionStateCommand, GetWorkerInfoCommand, MxCommand, MxCommandKind,
|
||||
MxCommandReply, MxCommandRequest, MxDataType, MxEvent, MxSparseArray, MxSparseElement,
|
||||
MxValue as ProtoMxValue, OpenSessionRequest, PingCommand, ReadBulkCommand, RegisterCommand,
|
||||
RemoveItemBulkCommand, RemoveItemCommand, SessionState, SetBufferedUpdateIntervalCommand,
|
||||
StreamEventsRequest, SubscribeBulkCommand, SubscribeResult, SuspendCommand, UnAdviseCommand,
|
||||
UnAdviseItemBulkCommand, UnregisterCommand, UnsubscribeBulkCommand, Write2BulkCommand,
|
||||
Write2BulkEntry, Write2Command, WriteBulkCommand, WriteBulkEntry, WriteCommand,
|
||||
WriteSecured2BulkCommand, WriteSecured2BulkEntry, WriteSecured2Command,
|
||||
UnAdviseItemBulkCommand, UnregisterCommand, UnsubscribeBulkCommand, WorkerInfoReply,
|
||||
Write2BulkCommand, Write2BulkEntry, Write2Command, WriteBulkCommand, WriteBulkEntry,
|
||||
WriteCommand, WriteSecured2BulkCommand, WriteSecured2BulkEntry, WriteSecured2Command,
|
||||
WriteSecuredBulkCommand, WriteSecuredBulkEntry, WriteSecuredCommand,
|
||||
};
|
||||
use crate::value::{MxStatus, MxValue, MxValueProjection};
|
||||
@@ -960,6 +961,90 @@ impl Session {
|
||||
.await
|
||||
}
|
||||
|
||||
/// Send a `Ping` diagnostic command to the worker. A successful return
|
||||
/// means the worker answered; `message` is forwarded for log correlation.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`Error::Command`] for non-OK statuses plus transport errors.
|
||||
pub async fn ping(&self, message: &str) -> Result<(), Error> {
|
||||
self.invoke(
|
||||
MxCommandKind::Ping,
|
||||
Payload::Ping(PingCommand {
|
||||
message: message.to_owned(),
|
||||
}),
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Fetch the gateway-side [`SessionState`] of this session.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`Error::MalformedReply`] when the reply lacks a session-state
|
||||
/// payload, plus the errors of [`invoke`](Self::invoke).
|
||||
pub async fn get_session_state(&self) -> Result<SessionState, Error> {
|
||||
let reply = self
|
||||
.invoke(
|
||||
MxCommandKind::GetSessionState,
|
||||
Payload::GetSessionState(GetSessionStateCommand {}),
|
||||
)
|
||||
.await?;
|
||||
match reply.payload {
|
||||
Some(mx_command_reply::Payload::SessionState(state)) => {
|
||||
Ok(SessionState::try_from(state.state).unwrap_or(SessionState::Unspecified))
|
||||
}
|
||||
_ => Err(Error::MalformedReply {
|
||||
detail: "get_session_state reply did not carry a SessionState payload".to_owned(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch worker process details (pid, version, MXAccess ProgID/CLSID).
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`Error::MalformedReply`] when the reply lacks a worker-info
|
||||
/// payload, plus the errors of [`invoke`](Self::invoke).
|
||||
pub async fn get_worker_info(&self) -> Result<WorkerInfoReply, Error> {
|
||||
let reply = self
|
||||
.invoke(
|
||||
MxCommandKind::GetWorkerInfo,
|
||||
Payload::GetWorkerInfo(GetWorkerInfoCommand {}),
|
||||
)
|
||||
.await?;
|
||||
match reply.payload {
|
||||
Some(mx_command_reply::Payload::WorkerInfo(info)) => Ok(info),
|
||||
_ => Err(Error::MalformedReply {
|
||||
detail: "get_worker_info reply did not carry a WorkerInfo payload".to_owned(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
/// Drain up to `max_events` queued events through the diagnostic command
|
||||
/// (distinct from the streaming [`events`](Self::events) surface). The
|
||||
/// reply is bounded server-side, so call repeatedly until it is empty.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns [`Error::MalformedReply`] when the reply lacks a drain-events
|
||||
/// payload, plus the errors of [`invoke`](Self::invoke).
|
||||
pub async fn drain_events(&self, max_events: u32) -> Result<Vec<MxEvent>, Error> {
|
||||
let reply = self
|
||||
.invoke(
|
||||
MxCommandKind::DrainEvents,
|
||||
Payload::DrainEvents(DrainEventsCommand { max_events }),
|
||||
)
|
||||
.await?;
|
||||
match reply.payload {
|
||||
Some(mx_command_reply::Payload::DrainEvents(drain)) => Ok(drain.events),
|
||||
_ => Err(Error::MalformedReply {
|
||||
detail: "drain_events reply did not carry a DrainEvents payload".to_owned(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
/// Issue a raw `Invoke` for an arbitrary command, without filtering on
|
||||
/// the protocol status. Useful when callers need the full reply for
|
||||
/// commands not yet wrapped by `Session`.
|
||||
|
||||
Reference in New Issue
Block a user