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,6 +1,6 @@
|
|||||||
use tracing_subscriber::fmt::format::FmtSpan;
|
use tracing_subscriber::fmt::format::FmtSpan;
|
||||||
mod server;
|
|
||||||
mod pki;
|
mod pki;
|
||||||
|
mod server;
|
||||||
|
|
||||||
fn set_console_logging() -> anyhow::Result<()> {
|
fn set_console_logging() -> anyhow::Result<()> {
|
||||||
// install global collector configured based on RUST_LOG env var.
|
// install global collector configured based on RUST_LOG env var.
|
||||||
@ -27,9 +27,18 @@ fn set_console_logging() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
|
// 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();
|
||||||
|
|
||||||
// Start the logger
|
// Start the logger
|
||||||
set_console_logging().unwrap();
|
set_console_logging().unwrap();
|
||||||
|
|
||||||
let _ = server::listen_accept().await;
|
let _ = server::listen_accept(pool.clone()).await;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
@ -10,18 +10,10 @@ use tokio::{
|
|||||||
|
|
||||||
/// Entry point for the main license server system.
|
/// Entry point for the main license server system.
|
||||||
/// Starts listening on port 9126 for license requests.
|
/// 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?;
|
let listener = TcpListener::bind(":::9126").await?;
|
||||||
tracing::info!("Listening on :::9126");
|
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 {
|
loop {
|
||||||
let (socket, address) = listener.accept().await?;
|
let (socket, address) = listener.accept().await?;
|
||||||
tracing::info!("Connection from {address:?}");
|
tracing::info!("Connection from {address:?}");
|
||||||
|
Loading…
Reference in New Issue
Block a user