Skip to content

Commit

Permalink
chore(su): remove pg dependency when booting db
Browse files Browse the repository at this point in the history
  • Loading branch information
VinceJuliano committed Nov 25, 2024
1 parent 452c1cc commit 45f69e9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 10 deletions.
40 changes: 40 additions & 0 deletions servers/su/src/domain/core/dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,46 @@ pub trait RouterDataStore: Send + Sync {
fn get_all_schedulers(&self) -> Result<Vec<Scheduler>, StoreErrorType>;
}

pub struct MockRouterDataStore;

#[async_trait]
impl RouterDataStore for MockRouterDataStore {
fn save_process_scheduler(
&self,
_process_scheduler: &ProcessScheduler,
) -> Result<String, StoreErrorType> {
unreachable!("save_process_scheduler is not implemented in MockRouterDataStore");
}

fn get_process_scheduler(
&self,
_process_id_in: &str,
) -> Result<ProcessScheduler, StoreErrorType> {
unreachable!("get_process_scheduler is not implemented in MockRouterDataStore");
}

fn save_scheduler(&self, _scheduler: &Scheduler) -> Result<String, StoreErrorType> {
unreachable!("save_scheduler is not implemented in MockRouterDataStore");
}

fn update_scheduler(&self, _scheduler: &Scheduler) -> Result<String, StoreErrorType> {
unreachable!("update_scheduler is not implemented in MockRouterDataStore");
}

fn get_scheduler(&self, _row_id_in: &i32) -> Result<Scheduler, StoreErrorType> {
unreachable!("get_scheduler is not implemented in MockRouterDataStore");
}

fn get_scheduler_by_url(&self, _url_in: &String) -> Result<Scheduler, StoreErrorType> {
unreachable!("get_scheduler_by_url is not implemented in MockRouterDataStore");
}

fn get_all_schedulers(&self) -> Result<Vec<Scheduler>, StoreErrorType> {
unreachable!("get_all_schedulers is not implemented in MockRouterDataStore");
}
}


pub trait CoreMetrics: Send + Sync {
fn get_process_observe(&self, duration: u128);
fn get_message_observe(&self, duration: u128);
Expand Down
32 changes: 22 additions & 10 deletions servers/su/src/domain/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::dal::RouterDataStore;
use std::sync::Arc;

use tokio::task::spawn_blocking;
Expand All @@ -12,7 +13,7 @@ use clients::{
wallet::FileWallet,
};
use config::AoConfig;
use core::dal::{Config, DataStore, Gateway, Log};
use core::dal::{Config, DataStore, Gateway, Log, MockRouterDataStore};
use logger::SuLog;

pub use clients::metrics::PromMetrics;
Expand All @@ -25,16 +26,26 @@ pub use store::migrate_to_disk;
pub async fn init_deps(mode: Option<String>, metrics_registry: prometheus::Registry) -> Arc<Deps> {
let logger: Arc<dyn Log> = SuLog::init();

let data_store = Arc::new(store::StoreClient::new().expect("Failed to create StoreClient"));
let d_clone = data_store.clone();
let router_data_store = data_store.clone();
let config = Arc::new(AoConfig::new(mode.clone()).expect("Failed to read configuration"));

match data_store.run_migrations() {
Ok(m) => logger.log(m),
Err(e) => logger.log(format!("{:?}", e)),
}
let data_store = if !config.use_local_store {
let ds = Arc::new(store::StoreClient::new().expect("Failed to create StoreClient"));
match ds.run_migrations() {
Ok(m) => logger.log(m),
Err(e) => logger.log(format!("{:?}", e)),
}
Some(ds)
} else {
None
};

let config = Arc::new(AoConfig::new(mode.clone()).expect("Failed to read configuration"));
let router_data_store: Arc<dyn RouterDataStore> = if !config.use_local_store {
data_store.clone().unwrap().clone()
} else {
Arc::new(
MockRouterDataStore {}
) as Arc<dyn RouterDataStore>
};

let main_data_store: Arc<dyn DataStore> = if config.use_local_store {
Arc::new(
Expand All @@ -45,11 +56,12 @@ pub async fn init_deps(mode: Option<String>, metrics_registry: prometheus::Regis
.expect("Failed to create LocalStoreClient"),
) as Arc<dyn DataStore>
} else {
data_store.clone()
data_store.clone().unwrap().clone()
};

if config.use_disk && config.mode != "router" {
let logger_clone = logger.clone();
let d_clone = data_store.clone().unwrap().clone();
/*
sync_bytestore is a blocking routine so we must
call spawn_blocking or the server wont start until
Expand Down
Binary file modified servers/su/su
Binary file not shown.

0 comments on commit 45f69e9

Please sign in to comment.