mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
Move the database pool creation to the main function. Failure is fatal.
This commit is contained in:
parent
6f6d746d43
commit
71135aa0b2
@ -1,35 +1,44 @@
|
||||
use tracing_subscriber::fmt::format::FmtSpan;
|
||||
mod server;
|
||||
mod pki;
|
||||
mod server;
|
||||
|
||||
fn set_console_logging() -> anyhow::Result<()> {
|
||||
// install global collector configured based on RUST_LOG env var.
|
||||
let subscriber = tracing_subscriber::fmt()
|
||||
// Use a more compact, abbreviated log format
|
||||
.compact()
|
||||
// Display source code file paths
|
||||
.with_file(true)
|
||||
// Display source code line numbers
|
||||
.with_line_number(true)
|
||||
// Display the thread ID an event was recorded on
|
||||
.with_thread_ids(true)
|
||||
// Don't display the event's target (module path)
|
||||
.with_target(false)
|
||||
// Include per-span timings
|
||||
.with_span_events(FmtSpan::CLOSE)
|
||||
// Build the subscriber
|
||||
.finish();
|
||||
// install global collector configured based on RUST_LOG env var.
|
||||
let subscriber = tracing_subscriber::fmt()
|
||||
// Use a more compact, abbreviated log format
|
||||
.compact()
|
||||
// Display source code file paths
|
||||
.with_file(true)
|
||||
// Display source code line numbers
|
||||
.with_line_number(true)
|
||||
// Display the thread ID an event was recorded on
|
||||
.with_thread_ids(true)
|
||||
// Don't display the event's target (module path)
|
||||
.with_target(false)
|
||||
// Include per-span timings
|
||||
.with_span_events(FmtSpan::CLOSE)
|
||||
// Build the subscriber
|
||||
.finish();
|
||||
|
||||
// Set the subscriber as the default
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
Ok(())
|
||||
// Set the subscriber as the default
|
||||
tracing::subscriber::set_global_default(subscriber)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
// Start the logger
|
||||
set_console_logging().unwrap();
|
||||
// Obtain the database pool
|
||||
let pool = pgdb::get_connection_pool(10).await;
|
||||
if pool.is_err() {
|
||||
tracing::error!("Unable to connect to the database");
|
||||
tracing::error!("{pool:?}");
|
||||
return Err(anyhow::Error::msg("Unable to connect to the database"));
|
||||
}
|
||||
let pool = pool.unwrap();
|
||||
|
||||
let _ = server::listen_accept().await;
|
||||
Ok(())
|
||||
// Start the logger
|
||||
set_console_logging().unwrap();
|
||||
|
||||
let _ = server::listen_accept(pool.clone()).await;
|
||||
Ok(())
|
||||
}
|
@ -10,18 +10,10 @@ use tokio::{
|
||||
|
||||
/// Entry point for the main license server system.
|
||||
/// Starts listening on port 9126 for license requests.
|
||||
pub async fn listen_accept() -> anyhow::Result<()> {
|
||||
pub async fn listen_accept(pool: Pool<Postgres>) -> anyhow::Result<()> {
|
||||
let listener = TcpListener::bind(":::9126").await?;
|
||||
tracing::info!("Listening on :::9126");
|
||||
|
||||
let pool = pgdb::get_connection_pool(10).await;
|
||||
if pool.is_err() {
|
||||
tracing::error!("Unable to connect to the database");
|
||||
tracing::error!("{pool:?}");
|
||||
return Err(anyhow::Error::msg("Unable to connect to the database"));
|
||||
}
|
||||
let pool = pool.unwrap();
|
||||
|
||||
loop {
|
||||
let (socket, address) = listener.accept().await?;
|
||||
tracing::info!("Connection from {address:?}");
|
||||
|
Loading…
Reference in New Issue
Block a user