mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
chore(rust): tidier libpk::main macro impl
This commit is contained in:
parent
7737850afb
commit
f9a6c2cefe
18 changed files with 90 additions and 64 deletions
|
|
@ -8,6 +8,7 @@ anyhow = { workspace = true }
|
|||
fred = { workspace = true }
|
||||
lazy_static = { workspace = true }
|
||||
metrics = { workspace = true }
|
||||
pk_macros = { path = "../macros" }
|
||||
sentry = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ pub mod state;
|
|||
pub mod _config;
|
||||
pub use crate::_config::CONFIG as config;
|
||||
|
||||
// functions in this file are only used by the main function below
|
||||
// functions in this file are only used by the main function in macros/entrypoint.rs
|
||||
|
||||
pub use pk_macros::main;
|
||||
|
||||
pub fn init_logging(component: &str) {
|
||||
let sentry_layer =
|
||||
|
|
@ -68,28 +70,3 @@ pub fn init_sentry() -> sentry::ClientInitGuard {
|
|||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! main {
|
||||
($component:expr) => {
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let _sentry_guard = libpk::init_sentry();
|
||||
// we might also be able to use env!("CARGO_CRATE_NAME") here
|
||||
libpk::init_logging($component);
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(async {
|
||||
if let Err(error) = libpk::init_metrics() {
|
||||
tracing::error!(?error, "failed to init metrics collector");
|
||||
};
|
||||
tracing::info!("hello world");
|
||||
if let Err(error) = real_main().await {
|
||||
tracing::error!(?error, "failed to run service");
|
||||
};
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue