Hastic standalone
https://hastic.io
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.5 KiB
52 lines
1.5 KiB
use crate::services::analytic_service::analytic_unit::types::AnalyticUnit; |
|
|
|
use std::sync::Arc; |
|
|
|
use chrono::Utc; |
|
|
|
use tokio::sync::{mpsc, RwLock}; |
|
|
|
use super::types::{AnalyticUnitRF, DetectionRunnerConfig}; |
|
use tokio::time::{sleep, Duration}; |
|
|
|
pub struct DetectionRunner { |
|
config: DetectionRunnerConfig, |
|
analytic_unit: AnalyticUnitRF, |
|
running_handler: Option<tokio::task::JoinHandle<()>>, |
|
} |
|
|
|
impl DetectionRunner { |
|
pub fn new(config: DetectionRunnerConfig, analytic_unit: AnalyticUnitRF) -> DetectionRunner { |
|
DetectionRunner { |
|
config, |
|
analytic_unit, |
|
running_handler: None, |
|
} |
|
} |
|
|
|
pub async fn run(&mut self, from: u64) { |
|
// TODO: get last detection timestamp from persistance |
|
// TODO: set lst detection from "now" |
|
if self.running_handler.is_some() { |
|
self.running_handler.as_mut().unwrap().abort(); |
|
} |
|
self.running_handler = Some(tokio::spawn({ |
|
// TODO: clone channel |
|
async move { |
|
// AnalyticService::run_learning(tx, cfg, ms, ss).await; |
|
// TODO: run detection "from" |
|
|
|
loop { |
|
// TODO: run detection periodically |
|
// TODO: use interval |
|
sleep(Duration::from_secs(100)).await; |
|
} |
|
} |
|
})); |
|
} |
|
|
|
pub async fn set_analytic_unit( |
|
analytic_unit: Arc<RwLock<Box<dyn AnalyticUnit + Send + Sync>>>, |
|
) { |
|
} |
|
}
|
|
|