diff options
Diffstat (limited to 'makima/src/bin/server.rs')
| -rw-r--r-- | makima/src/bin/server.rs | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/makima/src/bin/server.rs b/makima/src/bin/server.rs index 3ea3a67..bbc56fd 100644 --- a/makima/src/bin/server.rs +++ b/makima/src/bin/server.rs @@ -1,6 +1,6 @@ //! Makima Audio API Server binary. //! -//! This server provides WebSocket-based speech-to-text streaming. +//! This server provides WebSocket-based speech-to-text streaming with optional persistence. use std::sync::Arc; @@ -43,13 +43,29 @@ async fn main() -> anyhow::Result<()> { ); // Load ML models - let state = Arc::new( - AppState::new(¶keet_dir, ¶keet_eou_dir, &sortformer_path) - .map_err(|e| anyhow::anyhow!("Failed to load models: {}", e))?, - ); + let mut app_state = AppState::new(¶keet_dir, ¶keet_eou_dir, &sortformer_path) + .map_err(|e| anyhow::anyhow!("Failed to load models: {}", e))?; tracing::info!("Models loaded successfully"); + // Initialize database (optional - server works without it) + if let Ok(database_url) = std::env::var("POSTGRES_CONNECTION_URI") { + tracing::info!("Connecting to database..."); + match makima::db::create_pool(&database_url).await { + Ok(pool) => { + tracing::info!("Database connected successfully"); + app_state = app_state.with_db_pool(pool); + } + Err(e) => { + tracing::warn!("Failed to connect to database: {}. Running without persistence.", e); + } + } + } else { + tracing::info!("POSTGRES_CONNECTION_URI not set. Running without persistence."); + } + + let state = Arc::new(app_state); + // Run the server let addr = format!("0.0.0.0:{}", port); run_server(state, &addr).await |
