Files
posthog/rust/hook-api/src/main.rs
2024-09-05 06:19:25 +00:00

53 lines
1.3 KiB
Rust

use axum::Router;
use config::Config;
use envconfig::Envconfig;
use eyre::Result;
use common_metrics::setup_metrics_routes;
use hook_common::pgqueue::PgQueue;
mod config;
mod handlers;
common_alloc::used!();
async fn listen(app: Router, bind: String) -> Result<()> {
let listener = tokio::net::TcpListener::bind(bind).await?;
axum::serve(listener, app).await?;
Ok(())
}
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
let config = Config::init_from_env().expect("failed to load configuration from env");
let pg_queue = PgQueue::new(
// TODO: Coupling the queue name to the PgQueue object doesn't seem ideal from the api
// side, but we don't need more than one queue for now.
&config.queue_name,
&config.database_url,
config.max_pg_connections,
"hook-api",
)
.await
.expect("failed to initialize queue");
let app = handlers::add_routes(
Router::new(),
pg_queue,
config.hog_mode,
config.max_body_size,
config.concurrency_limit,
);
let app = setup_metrics_routes(app);
match listen(app, config.bind()).await {
Ok(_) => {}
Err(e) => tracing::error!("failed to start hook-api http server, {}", e),
}
}