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:
Aiden McClelland
2024-07-25 11:44:51 -06:00
committed by GitHub
parent ab465a755e
commit b36b62c68e
113 changed files with 4853 additions and 2517 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,3 @@
pub mod eq_map;
pub use eq_map::EqMap;

View File

@@ -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;

View File

@@ -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
}
}