Add notifier to break relay loop
This commit is contained in:
parent
83c1f033d5
commit
8785186dfa
12 changed files with 124 additions and 45 deletions
emgauwa-controller/src
|
@ -1,5 +1,4 @@
|
|||
use actix::Actor;
|
||||
use emgauwa_lib::constants::WEBSOCKET_RETRY_TIMEOUT;
|
||||
use emgauwa_lib::db;
|
||||
use emgauwa_lib::db::{DbController, DbJunctionRelaySchedule, DbRelay, DbSchedule};
|
||||
use emgauwa_lib::errors::EmgauwaError;
|
||||
|
@ -8,11 +7,10 @@ use emgauwa_lib::types::ControllerUid;
|
|||
use emgauwa_lib::utils::init_logging;
|
||||
use sqlx::pool::PoolConnection;
|
||||
use sqlx::Sqlite;
|
||||
use tokio::time;
|
||||
|
||||
use crate::relay_loop::run_relay_loop;
|
||||
use crate::relay_loop::run_relays_loop;
|
||||
use crate::settings::Settings;
|
||||
use crate::ws::run_websocket;
|
||||
use crate::ws::run_ws_loop;
|
||||
|
||||
mod app_state;
|
||||
mod driver;
|
||||
|
@ -110,18 +108,11 @@ async fn main() -> Result<(), std::io::Error> {
|
|||
settings.core.host, settings.core.port
|
||||
);
|
||||
|
||||
tokio::spawn(run_relay_loop(settings));
|
||||
|
||||
loop {
|
||||
let run_result = run_websocket(pool.clone(), &app_state, &url).await;
|
||||
if let Err(err) = run_result {
|
||||
log::error!("Error running websocket: {}", err);
|
||||
}
|
||||
|
||||
log::info!(
|
||||
"Retrying to connect in {} seconds...",
|
||||
WEBSOCKET_RETRY_TIMEOUT.as_secs()
|
||||
);
|
||||
time::sleep(WEBSOCKET_RETRY_TIMEOUT).await;
|
||||
tokio::select! {
|
||||
_ = run_relays_loop(app_state.clone()) => {},
|
||||
_ = run_ws_loop(pool.clone(), app_state.clone(), url) => {},
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue