Browse Source

config patch continue

pull/25/head
Alexey Velikiy 3 years ago
parent
commit
1e8c1aebd6
  1. 2
      server/src/api/analytics.rs
  2. 9
      server/src/services/analytic_service/analytic_client.rs
  3. 5
      server/src/services/analytic_service/analytic_service.rs
  4. 3
      server/src/services/analytic_service/types.rs

2
server/src/api/analytics.rs

@ -119,7 +119,7 @@ mod handlers {
pub async fn patch_config(client: Client, obj: Value) -> Result<impl warp::Reply, warp::Rejection> {
println!("{:?}", obj);
// println!("{:?}", obj);
match client.get_config().await {
Ok(cf) => Ok(API::json(&cf)),
Err(e) => {

9
server/src/services/analytic_service/analytic_client.rs

@ -1,3 +1,4 @@
use serde_json::Value;
use tokio::sync::mpsc;
use tokio::sync::oneshot;
@ -43,6 +44,14 @@ impl AnalyticClient {
Ok(r)
}
pub async fn patch_config(&self, patch_obj: Value) -> anyhow::Result<()> {
let (tx, rx) = oneshot::channel();
let req = AnalyticServiceMessage::Request(RequestType::PatchConfig(patch_obj, tx));
self.tx.send(req).await?;
rx.await?;
Ok(())
}
// pub async fn get_train(&self) -> anyhow::Result<LearningTrain> {
// let (tx, rx) = oneshot::channel();
// let req = AnalyticServiceMessage::Request(RequestType::GetLearningTrain(tx));

5
server/src/services/analytic_service/analytic_service.rs

@ -168,6 +168,11 @@ impl AnalyticService {
// }
RequestType::GetConfig(tx) => {
tx.send(self.analytic_unit_config.clone()).unwrap();
},
RequestType::PatchConfig(patch_obj, tx) => {
// TODO: path config
// TODO: run learning if config type changed
tx.send(()).unwrap();
}
};
}

3
server/src/services/analytic_service/types.rs

@ -9,6 +9,7 @@ use super::analytic_unit::{
use anyhow::Result;
use serde::Serialize;
use serde_json::Value;
use tokio::sync::oneshot;
use crate::services::analytic_service::analytic_unit::types::AnalyticUnit;
@ -72,6 +73,8 @@ pub enum RequestType {
RunLearning,
RunDetection(DetectionTask),
GetStatus(oneshot::Sender<LearningStatus>),
// TODO: make type of Value
PatchConfig(Value, oneshot::Sender<()>),
GetConfig(oneshot::Sender<AnalyticUnitConfig>),
// GetLearningTrain(oneshot::Sender<LearningTrain>),
}

Loading…
Cancel
Save