From b2cdab4721c59b6916f1ea740684222dde24205f Mon Sep 17 00:00:00 2001 From: James Prestwich Date: Mon, 12 Jul 2021 16:32:57 -0700 Subject: [PATCH] chore: standardize agent main files --- rust/kathy/src/main.rs | 5 ++--- rust/processor/src/main.rs | 18 ++++++------------ rust/relayer/src/main.rs | 19 +++++-------------- rust/updater/src/main.rs | 19 +++++-------------- rust/watcher/src/main.rs | 19 +++++-------------- 5 files changed, 23 insertions(+), 57 deletions(-) diff --git a/rust/kathy/src/main.rs b/rust/kathy/src/main.rs index d3d252252..e58ec91ed 100644 --- a/rust/kathy/src/main.rs +++ b/rust/kathy/src/main.rs @@ -15,12 +15,11 @@ use crate::{kathy::Kathy, settings::KathySettings as Settings}; async fn _main() -> Result<()> { color_eyre::install()?; - let settings = Settings::new()?; settings.base.tracing.try_init_tracing()?; - let kathy = Kathy::from_settings(settings).await?; - kathy.run_all().await?; + let agent = Kathy::from_settings(settings).await?; + agent.run_all().await?; Ok(()) } diff --git a/rust/processor/src/main.rs b/rust/processor/src/main.rs index b59b6735f..d953afe9d 100644 --- a/rust/processor/src/main.rs +++ b/rust/processor/src/main.rs @@ -17,26 +17,20 @@ use color_eyre::Result; use crate::{processor::Processor, settings::ProcessorSettings as Settings}; use optics_base::agent::OpticsAgent; -async fn _main(settings: Settings) -> Result<()> { - let processor = Processor::from_settings(settings).await?; - processor.run_all().await?; - - Ok(()) -} - -fn setup() -> Result { +async fn _main() -> Result<()> { color_eyre::install()?; let settings = Settings::new()?; settings.base.tracing.try_init_tracing()?; - Ok(settings) + + let agent = Processor::from_settings(settings).await?; + agent.run_all().await?; + Ok(()) } fn main() -> Result<()> { - let settings = setup()?; - tokio::runtime::Builder::new_current_thread() .enable_all() .build() .unwrap() - .block_on(_main(settings)) + .block_on(_main()) } diff --git a/rust/relayer/src/main.rs b/rust/relayer/src/main.rs index 50f6e932f..c7c34ca3d 100644 --- a/rust/relayer/src/main.rs +++ b/rust/relayer/src/main.rs @@ -19,29 +19,20 @@ use optics_base::agent::OpticsAgent; use crate::{relayer::Relayer, settings::RelayerSettings as Settings}; -async fn _main(settings: Settings) -> Result<()> { - let relayer = Relayer::from_settings(settings).await?; - relayer.run_all().await?; - - Ok(()) -} - -fn setup() -> Result { +async fn _main() -> Result<()> { color_eyre::install()?; - let settings = Settings::new()?; - settings.base.tracing.try_init_tracing()?; - Ok(settings) + let agent = Relayer::from_settings(settings).await?; + agent.run_all().await?; + Ok(()) } fn main() -> Result<()> { - let settings = setup()?; - tokio::runtime::Builder::new_current_thread() .enable_all() .build() .unwrap() - .block_on(_main(settings)) + .block_on(_main()) } diff --git a/rust/updater/src/main.rs b/rust/updater/src/main.rs index 4cba15ac0..f53d050cf 100644 --- a/rust/updater/src/main.rs +++ b/rust/updater/src/main.rs @@ -16,29 +16,20 @@ use optics_base::agent::OpticsAgent; use crate::{settings::UpdaterSettings as Settings, updater::Updater}; -async fn _main(settings: Settings) -> Result<()> { - let updater = Updater::from_settings(settings).await?; - - updater.run("").await??; - - Ok(()) -} - -fn setup() -> Result { +async fn _main() -> Result<()> { color_eyre::install()?; - let settings = Settings::new()?; settings.base.tracing.try_init_tracing()?; - Ok(settings) + let agent = Updater::from_settings(settings).await?; + agent.run_all().await?; + Ok(()) } fn main() -> Result<()> { - let settings = setup()?; - tokio::runtime::Builder::new_current_thread() .enable_all() .build() .unwrap() - .block_on(_main(settings)) + .block_on(_main()) } diff --git a/rust/watcher/src/main.rs b/rust/watcher/src/main.rs index 940b08400..0e9f967f9 100644 --- a/rust/watcher/src/main.rs +++ b/rust/watcher/src/main.rs @@ -18,29 +18,20 @@ use optics_base::agent::OpticsAgent; use crate::{settings::WatcherSettings as Settings, watcher::Watcher}; -async fn _main(settings: Settings) -> Result<()> { - let watcher = Watcher::from_settings(settings).await?; - watcher.run_all().await?; - - Ok(()) -} - -fn setup() -> Result { +async fn _main() -> Result<()> { color_eyre::install()?; - let settings = Settings::new()?; - settings.base.tracing.try_init_tracing()?; - Ok(settings) + let agent = Watcher::from_settings(settings).await?; + agent.run_all().await?; + Ok(()) } fn main() -> Result<()> { - let settings = setup()?; - tokio::runtime::Builder::new_current_thread() .enable_all() .build() .unwrap() - .block_on(_main(settings)) + .block_on(_main()) }