Implement /rpc_server_snapshot endpoint
This returns a JSON snapshot of the state of the server
This commit is contained in:
parent
6a32d55d85
commit
742dd75041
6 changed files with 68 additions and 8 deletions
|
@ -33,6 +33,7 @@ use rpc::{
|
|||
proto::{self, AnyTypedEnvelope, EntityMessage, EnvelopedMessage, RequestMessage},
|
||||
Connection, ConnectionId, Peer, Receipt, TypedEnvelope,
|
||||
};
|
||||
use serde::{Serialize, Serializer};
|
||||
use std::{
|
||||
any::TypeId,
|
||||
future::Future,
|
||||
|
@ -85,6 +86,7 @@ pub struct Server {
|
|||
notifications: Option<mpsc::UnboundedSender<()>>,
|
||||
}
|
||||
|
||||
|
||||
pub trait Executor: Send + Clone {
|
||||
type Sleep: Send + Future;
|
||||
fn spawn_detached<F: 'static + Send + Future<Output = ()>>(&self, future: F);
|
||||
|
@ -107,6 +109,23 @@ struct StoreWriteGuard<'a> {
|
|||
_not_send: PhantomData<Rc<()>>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct ServerSnapshot<'a> {
|
||||
peer: &'a Peer,
|
||||
#[serde(serialize_with = "serialize_deref")]
|
||||
store: RwLockReadGuard<'a, Store>,
|
||||
}
|
||||
|
||||
pub fn serialize_deref<S, T, U>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
T: Deref<Target = U>,
|
||||
U: Serialize
|
||||
{
|
||||
Serialize::serialize(value.deref(), serializer)
|
||||
}
|
||||
|
||||
|
||||
impl Server {
|
||||
pub fn new(
|
||||
app_state: Arc<AppState>,
|
||||
|
@ -1469,6 +1488,13 @@ impl Server {
|
|||
_not_send: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn snapshot<'a>(self: &'a Arc<Self>) -> ServerSnapshot<'a> {
|
||||
ServerSnapshot {
|
||||
store: self.store.read().await,
|
||||
peer: &self.peer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Deref for StoreReadGuard<'a> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue