maps-service/validation/src/main.rs

41 lines
1.1 KiB
Rust
Raw Normal View History

2024-12-03 05:09:59 +00:00
mod nats_types;
2024-12-03 06:09:01 +00:00
mod publisher;
2024-12-03 05:15:10 +00:00
mod validator;
2024-11-26 01:30:55 +00:00
2024-12-03 06:09:01 +00:00
#[allow(dead_code)]
#[derive(Debug)]
enum StartupError{
Connect(async_nats::ConnectError),
Subscribe(async_nats::SubscribeError),
}
2024-12-03 06:52:01 +00:00
impl std::fmt::Display for StartupError{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}")
}
}
impl std::error::Error for StartupError{}
2024-12-03 06:09:01 +00:00
2024-12-03 05:15:10 +00:00
#[tokio::main]
2024-12-03 06:09:01 +00:00
async fn main()->Result<(),StartupError>{
2024-12-03 06:52:01 +00:00
// cookies and clouds
let cookie_context=rbx_asset::cookie::CookieContext::new(rbx_asset::cookie::Cookie::new("".to_owned()));
let cloud_context=rbx_asset::cloud::CloudContext::new(rbx_asset::cloud::ApiKey::new("".to_owned()));
// nats
2024-12-03 06:09:01 +00:00
let nasty=async_nats::connect("nats").await.map_err(StartupError::Connect)?;
2024-12-03 06:52:01 +00:00
// connect to nats
2024-12-03 06:09:01 +00:00
let (publisher,validator)=tokio::try_join!(
2024-12-03 06:52:01 +00:00
publisher::Publisher::new(nasty.clone(),cookie_context.clone(),cloud_context),
validator::Validator::new(nasty,cookie_context)
2024-12-03 06:09:01 +00:00
).map_err(StartupError::Subscribe)?;
2024-12-03 06:52:01 +00:00
2024-12-03 06:09:01 +00:00
// publisher thread
tokio::spawn(publisher.run());
2024-12-03 06:52:01 +00:00
2024-12-03 06:09:01 +00:00
// run validator on the main thread indefinitely
validator.run().await;
2024-12-03 06:52:01 +00:00
2024-12-03 06:09:01 +00:00
Ok(())
2024-11-26 01:30:55 +00:00
}