mirror of
https://github.com/moghtech/komodo.git
synced 2026-03-11 17:44:19 -05:00
resolver trait
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1031,6 +1031,7 @@ name = "monitor_periphery"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
"async_timing_util",
|
||||
"axum",
|
||||
"bollard",
|
||||
@@ -1055,6 +1056,7 @@ dependencies = [
|
||||
name = "monitor_types"
|
||||
version = "1.0.0"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"diff-struct",
|
||||
"serde",
|
||||
"strum",
|
||||
|
||||
@@ -36,6 +36,7 @@ typeshare = "1.0.1"
|
||||
strum = "0.24"
|
||||
strum_macros = "0.24"
|
||||
sysinfo = "0.29"
|
||||
async-trait = "0.1"
|
||||
# mogh
|
||||
run_command = { version = "0.0.6", features = ["async_tokio"] }
|
||||
slack = { package = "slack_client_rs", version = "0.0.8" }
|
||||
|
||||
@@ -11,4 +11,5 @@ serde.workspace = true
|
||||
diff-struct.workspace = true
|
||||
typeshare.workspace = true
|
||||
strum.workspace = true
|
||||
strum_macros.workspace = true
|
||||
strum_macros.workspace = true
|
||||
async-trait.workspace = true
|
||||
@@ -1,11 +1,11 @@
|
||||
use diff::Diff;
|
||||
use serde::{Deserialize, Serialize, de::DeserializeOwned};
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
use strum_macros::{Display, EnumString};
|
||||
use typeshare::typeshare;
|
||||
|
||||
pub mod core_api;
|
||||
pub mod periphery_api;
|
||||
pub mod entities;
|
||||
pub mod periphery_api;
|
||||
|
||||
#[typeshare(serialized_as = "number")]
|
||||
pub type I64 = i64;
|
||||
@@ -138,6 +138,11 @@ pub trait HasResponse: Serialize + std::fmt::Debug {
|
||||
fn req_type() -> &'static str;
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
pub trait Resolve<Req: HasResponse> {
|
||||
async fn resolve(&self, req: Req) -> Req::Response;
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! impl_has_response {
|
||||
($req:ty, $res:ty) => {
|
||||
@@ -148,4 +153,5 @@ macro_rules! impl_has_response {
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ log.workspace = true
|
||||
simple_logger.workspace = true
|
||||
uuid.workspace = true
|
||||
sysinfo.workspace = true
|
||||
async-trait.workspace = true
|
||||
# mogh
|
||||
async_timing_util.workspace = true
|
||||
merge_config_files.workspace = true
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use anyhow::{anyhow, Context};
|
||||
use monitor_types::periphery_api::{requests::GetVersionResponse, PeripheryRequest};
|
||||
use monitor_types::{periphery_api::{requests::{GetVersionResponse, GetHealth, GetHealthResponse, GetVersion}, PeripheryRequest}, Resolve};
|
||||
|
||||
use crate::state::State;
|
||||
|
||||
@@ -22,3 +22,17 @@ fn get_version() -> anyhow::Result<String> {
|
||||
})
|
||||
.context("failed to convert version to string")
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Resolve<GetHealth> for State {
|
||||
async fn resolve(&self, _: GetHealth) -> GetHealthResponse {
|
||||
GetHealthResponse {}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl Resolve<GetVersion> for State {
|
||||
async fn resolve(&self, _: GetVersion) -> GetVersionResponse {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user