Browse Source

detection runner started notification

detection_runner_updade
Alexey Velikiy 2 years ago
parent
commit
c74abb1bbd
  1. 3
      server/src/services/analytic_service/analytic_service.rs
  2. 15
      server/src/services/analytic_service/detection_runner.rs
  3. 1
      server/src/services/analytic_service/types.rs

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

@ -232,6 +232,9 @@ impl AnalyticService {
match res {
Ok(response_type) => {
match response_type {
ResponseType::DetectionRunnerStarted(from) => {
println!("Detection runner started from {}", from)
}
ResponseType::LearningStarted => {
self.analytic_unit_learning_status = LearningStatus::Learning
}

15
server/src/services/analytic_service/detection_runner.rs

@ -6,7 +6,7 @@ use chrono::Utc;
use tokio::sync::{mpsc, RwLock};
use super::types::{AnalyticServiceMessage, AnalyticUnitRF, DetectionRunnerConfig};
use super::types::{AnalyticServiceMessage, AnalyticUnitRF, DetectionRunnerConfig, ResponseType};
use tokio::time::{sleep, Duration};
pub struct DetectionRunner {
@ -39,6 +39,7 @@ impl DetectionRunner {
self.running_handler = Some(tokio::spawn({
// TODO: clone channel
let cfg = self.config.clone();
let tx = self.tx.clone();
async move {
// TODO: run detection "from" for big timespan
// TODO: parse detections to webhooks
@ -46,7 +47,17 @@ impl DetectionRunner {
// TODO: save last detection
// TODO: handle case when detection is in the end and continues after "now"
println!("detection runner started from {}", from);
match tx
.send(AnalyticServiceMessage::Response(Ok(
ResponseType::DetectionRunnerStarted(from),
)))
.await
{
Ok(_) => {}
Err(_e) => println!("Fail to send detection runner started notification"),
}
loop {
// TODO: run detection periodically
sleep(Duration::from_secs(cfg.interval)).await;

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

@ -43,6 +43,7 @@ impl Default for LearningTrain {
}
pub enum ResponseType {
DetectionRunnerStarted(u64),
LearningStarted,
LearningFinished(Box<dyn AnalyticUnit + Send + Sync>),
LearningFinishedEmpty,

Loading…
Cancel
Save