omni_orchestrator/initialization/
launch_server.rs

1use crate::server::build_rocket;
2// use crate::{CLUSTER_MANAGER}; // removed unused import
3use crate::db_manager::DatabaseManager;
4use crate::state::SharedState;
5// use libomni::types::db::auth::AuthConfig; // removed unused import
6use std::sync::Arc;
7use tokio::sync::RwLock;
8use colored::Colorize;
9
10/// Builds and launches the Rocket server with the provided configuration and dependencies.
11///
12/// # Arguments
13/// * `port` - The port to bind the server to.
14/// * `db_manager` - Shared database manager instance.
15/// * `pool` - Main database pool.
16/// * `cluster_manager` - Shared cluster manager instance.
17/// * `clickhouse_client` - ClickHouse client instance.
18/// * `shared_state_for_server` - Shared state for the server.
19///
20/// # Errors
21/// Returns an error if the Rocket server fails to launch.
22pub async fn launch_server(
23    port: u16,
24    db_manager: Arc<DatabaseManager>,
25    pool: sqlx::MySqlPool,
26    cluster_manager: Arc<RwLock<crate::cluster::ClusterManager>>,
27    clickhouse_client: clickhouse::Client,
28    shared_state_for_server: Arc<RwLock<SharedState>>,
29) -> Result<(), Box<dyn std::error::Error>> {
30    let auth_config = super::create_auth_config();
31    let rocket_with_routes = build_rocket(
32        port,
33        db_manager,
34        pool,
35        cluster_manager,
36        clickhouse_client,
37        shared_state_for_server,
38        auth_config,
39    );
40    log::info!("{}", "🚀 LAUNCHING SERVER...".bright_cyan().bold());
41    rocket_with_routes.launch().await?;
42    Ok(())
43}