|
|
|
@ -276,29 +276,46 @@ impl AnalyticService {
|
|
|
|
|
fn patch_config(&mut self, patch: PatchConfig, tx: oneshot::Sender<()>) { |
|
|
|
|
|
|
|
|
|
let my_id = self.analytic_unit_service.get_config_id(&self.analytic_unit_config); |
|
|
|
|
|
|
|
|
|
let patch_id = patch.get_type_id(); |
|
|
|
|
|
|
|
|
|
let same_type = my_id == patch_id; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: need_learning and same_type logic overlaps, there is a way to optimise this
|
|
|
|
|
let need_learning = self.analytic_unit_config.patch_needs_learning(&patch); |
|
|
|
|
|
|
|
|
|
if same_type { |
|
|
|
|
// TODO: check when learning should be started
|
|
|
|
|
let new_conf = patch.get_new_config(); |
|
|
|
|
self.analytic_unit_config = new_conf.clone(); |
|
|
|
|
self.analytic_unit_service.update_config_by_id(&my_id, &new_conf).unwrap(); |
|
|
|
|
|
|
|
|
|
if self.analytic_unit.is_some() { |
|
|
|
|
tokio::spawn({ |
|
|
|
|
let au = self.analytic_unit.clone(); |
|
|
|
|
let cfg = self.analytic_unit_config.clone(); |
|
|
|
|
async move { |
|
|
|
|
au.unwrap().write().await.set_config(cfg); |
|
|
|
|
match tx.send(()) { |
|
|
|
|
Ok(_) => {} |
|
|
|
|
Err(_e) => { |
|
|
|
|
println!("Can`t send patch config notification"); |
|
|
|
|
} |
|
|
|
|
if need_learning { |
|
|
|
|
self.consume_request(RequestType::RunLearning); |
|
|
|
|
match tx.send(()) { |
|
|
|
|
Ok(_) => {} |
|
|
|
|
Err(_e) => { |
|
|
|
|
println!("Can`t send patch config notification"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
return; |
|
|
|
|
} else { |
|
|
|
|
tokio::spawn({ |
|
|
|
|
let au = self.analytic_unit.clone(); |
|
|
|
|
let cfg = self.analytic_unit_config.clone(); |
|
|
|
|
async move { |
|
|
|
|
au.unwrap().write().await.set_config(cfg); |
|
|
|
|
match tx.send(()) { |
|
|
|
|
Ok(_) => {} |
|
|
|
|
Err(_e) => { |
|
|
|
|
println!("Can`t send patch config notification"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// TODO: check if we need this else
|
|
|
|
|
match tx.send(()) { |
|
|
|
@ -309,7 +326,6 @@ impl AnalyticService {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// TODO: extracdt from db
|
|
|
|
|
let new_conf = self.analytic_unit_service.get_config_by_id(&patch_id).unwrap(); |
|
|
|
|
self.analytic_unit_config = new_conf.clone(); |
|
|
|
|
self.consume_request(RequestType::RunLearning); |
|
|
|
@ -320,18 +336,6 @@ impl AnalyticService {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: update analytic_unit config if some
|
|
|
|
|
// TODO: save updated
|
|
|
|
|
// TODO: run learning when different
|
|
|
|
|
// TODO: run learning when it's necessary
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub async fn serve(&mut self) { |
|
|
|
|