use dm_database_parser_sqllog::Sqllog;
pub trait LogProcessor: Send + Sync + std::fmt::Debug {
fn process(&self, record: &Sqllog) -> bool;
fn process_with_meta(&self, record: &Sqllog) -> bool {
self.process(record)
}
}
#[derive(Debug, Default)]
pub struct Pipeline {
processors: Vec<Box<dyn LogProcessor>>,
}
impl Pipeline {
#[must_use]
pub fn new() -> Self {
Self::default()
}
pub fn add(&mut self, processor: Box<dyn LogProcessor>) {
self.processors.push(processor);
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.processors.is_empty()
}
#[inline]
#[must_use]
pub fn run_with_meta(&self, record: &Sqllog) -> bool {
self.processors.iter().all(|p| p.process_with_meta(record))
}
}