mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
Feature/callbacks (#2678)
* wip * initialize callbacks * wip * smtp * list_service_interfaces * wip * wip * fix domains * fix hostname handling in NetService * misc fixes * getInstalledPackages * misc fixes * publish v6 lib * refactor service effects * fix import * fix container runtime * fix tests * apply suggestions from review
This commit is contained in:
1213
core/startos/src/util/collections/eq_map.rs
Normal file
1213
core/startos/src/util/collections/eq_map.rs
Normal file
File diff suppressed because it is too large
Load Diff
3
core/startos/src/util/collections/mod.rs
Normal file
3
core/startos/src/util/collections/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub mod eq_map;
|
||||
|
||||
pub use eq_map::EqMap;
|
||||
@@ -34,8 +34,10 @@ use crate::shutdown::Shutdown;
|
||||
use crate::util::io::create_file;
|
||||
use crate::util::serde::{deserialize_from_str, serialize_display};
|
||||
use crate::{Error, ErrorKind, ResultExt as _};
|
||||
|
||||
pub mod actor;
|
||||
pub mod clap;
|
||||
pub mod collections;
|
||||
pub mod cpupower;
|
||||
pub mod crypto;
|
||||
pub mod future;
|
||||
|
||||
@@ -138,6 +138,31 @@ impl RpcClient {
|
||||
err.data = Some(json!("RpcClient thread has terminated"));
|
||||
Err(err)
|
||||
}
|
||||
|
||||
pub async fn notify<T: RpcMethod>(
|
||||
&mut self,
|
||||
method: T,
|
||||
params: T::Params,
|
||||
) -> Result<(), RpcError>
|
||||
where
|
||||
T: Serialize,
|
||||
T::Params: Serialize,
|
||||
{
|
||||
let request = RpcRequest {
|
||||
id: None,
|
||||
method,
|
||||
params,
|
||||
};
|
||||
self.writer
|
||||
.write_all((dbg!(serde_json::to_string(&request))? + "\n").as_bytes())
|
||||
.await
|
||||
.map_err(|e| {
|
||||
let mut err = rpc_toolkit::yajrc::INTERNAL_ERROR.clone();
|
||||
err.data = Some(json!(e.to_string()));
|
||||
err
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -224,4 +249,36 @@ impl UnixRpcClient {
|
||||
};
|
||||
res
|
||||
}
|
||||
|
||||
pub async fn notify<T: RpcMethod>(&self, method: T, params: T::Params) -> Result<(), RpcError>
|
||||
where
|
||||
T: Serialize + Clone,
|
||||
T::Params: Serialize + Clone,
|
||||
{
|
||||
let mut tries = 0;
|
||||
let res = loop {
|
||||
let mut client = self.pool.clone().get().await?;
|
||||
if client.handler.is_finished() {
|
||||
client.destroy();
|
||||
continue;
|
||||
}
|
||||
let res = client.notify(method.clone(), params.clone()).await;
|
||||
match &res {
|
||||
Err(e) if e.code == rpc_toolkit::yajrc::INTERNAL_ERROR.code => {
|
||||
let mut e = Error::from(e.clone());
|
||||
e.kind = ErrorKind::Filesystem;
|
||||
tracing::error!("{e}");
|
||||
tracing::debug!("{e:?}");
|
||||
client.destroy();
|
||||
}
|
||||
_ => break res,
|
||||
}
|
||||
tries += 1;
|
||||
if tries > MAX_TRIES {
|
||||
tracing::warn!("Max Tries exceeded");
|
||||
break res;
|
||||
}
|
||||
};
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user