pub fn run(
    conn_pool: storage::ConnectionPool,
    interval: Duration,
    stop: mpsc::Receiver<()>,
) -> ObservedState {
    info!("starting observer mode");
    let storage = conn_pool.access_storage().expect("failed to access db");
    let mut observed_state = ObservedState::new(storage);
    observed_state
        .init()
        .expect("failed to init observed state");
    loop {
        let exit = match stop.try_recv() {
            Err(mpsc::TryRecvError::Empty) => false,
            Err(e) => {
                panic!("stop channel recv error: {}", e);
            }
            Ok(_) => true,
        };
        thread::sleep(interval);
        observed_state
            .update()
            .expect("failed to update observed state");
        if exit {
            break;
        }
    }
    observed_state
}
/// Accumulate state from db continuously and return that state on stop signal.
///
/// # Panics
/// Panics on failed connection to db.
Accumulate state from db continuously and return that state on stop signal.
Accumulate state from db continuously and return that state on stop signal .
pub fn run(
    conn_pool: storage::ConnectionPool,
    interval: Duration,
    stop: mpsc::Receiver<()>,
) -> ObservedState {
    info!("starting observer mode");
    let storage = conn_pool.access_storage().expect("failed to access db");
    let mut observed_state = ObservedState::new(storage);
    observed_state
        .init()
        .expect("failed to init observed state");
    loop {
        let exit = match stop.try_recv() {
            Err(mpsc::TryRecvError::Empty) => false,
            Err(e) => {
                panic!("stop channel recv error: {}", e);
            }
            Ok(_) => true,
        };
        thread::sleep(interval);
        observed_state
            .update()
            .expect("failed to update observed state");
        if exit {
            break;
        }
    }
    observed_state
}
pub fn run ( conn_pool : storage :: ConnectionPool , interval : Duration , stop : mpsc :: Receiver < ( ) > , ) -> ObservedState { info ! ( " " ) ; let storage = conn_pool . access_storage ( ) . expect ( " " ) ; let mut observed_state = ObservedState :: new ( storage ) ; observed_state . init ( ) . expect ( " " ) ; loop { let exit = match stop . try_recv ( ) { Err ( mpsc :: TryRecvError :: Empty ) => false , Err ( e ) => { panic ! ( " " e ) ; } Ok ( _ ) => true , } ; thread :: sleep ( interval ) ; observed_state . update ( ) . expect ( " " ) ; if exit { break ; } } observed_state }
Accumulate state from db continuously and return that state on stop signal.
Accumulate state from db continuously and return that state on stop signal .
conn_pool
storage::ConnectionPool
interval
Duration
stop
mpsc::Receiver<()>
panics
Panics on failed connection to db.
Panics on failed connection to db .