65 lines
1.6 KiB
Rust
65 lines
1.6 KiB
Rust
use crate::{bot::Bot, gitea::WebhookType, state::AppState};
|
|
use dotenvy::dotenv;
|
|
use tracing::{info, warn};
|
|
use tracing_subscriber::{EnvFilter, fmt, layer::SubscriberExt, util::SubscriberInitExt};
|
|
|
|
mod api;
|
|
mod bot;
|
|
mod bot_actions;
|
|
mod consts;
|
|
mod env;
|
|
mod errors;
|
|
mod gitea;
|
|
mod open_router;
|
|
mod state;
|
|
|
|
fn main() -> anyhow::Result<()> {
|
|
dotenv().ok();
|
|
|
|
tracing_subscriber::registry()
|
|
.with(fmt::layer())
|
|
.with(
|
|
EnvFilter::try_from_default_env() // lit RUST_LOG depuis l'env
|
|
.unwrap_or_else(|_| EnvFilter::new("info")),
|
|
)
|
|
.init();
|
|
|
|
let _sentry_guard = if let Ok(sentry_dsn) = env::try_get_env("SENTRY_DSN") {
|
|
info!("Initialize sentry");
|
|
|
|
Some(sentry::init((
|
|
sentry_dsn,
|
|
sentry::ClientOptions {
|
|
release: sentry::release_name!(),
|
|
send_default_pii: true,
|
|
..Default::default()
|
|
},
|
|
)))
|
|
} else {
|
|
warn!("SENTRY_DSN not set, sentry will not be initialized");
|
|
None
|
|
};
|
|
|
|
tokio::runtime::Runtime::new()?.block_on(run())
|
|
}
|
|
|
|
async fn run() -> anyhow::Result<()> {
|
|
let config = env::load_config()?;
|
|
|
|
info!(
|
|
port = config.http_port,
|
|
model = %config.open_router_model,
|
|
gitea_url = %config.gitea_url,
|
|
bot_name = %config.bot_name,
|
|
"Starting Herald"
|
|
);
|
|
|
|
let bot = Bot::new(config.clone())?;
|
|
let (tx, rx) = tokio::sync::mpsc::channel::<WebhookType>(config.bot_max_concurrent * 2);
|
|
let app_state = AppState { bot_tx: tx, config };
|
|
|
|
tokio::try_join!(bot.start(rx), api::start(app_state))?;
|
|
|
|
Ok(())
|
|
}
|