diff options
| author | soryu <soryu@soryu.co> | 2025-12-23 02:14:58 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2025-12-23 14:47:18 +0000 |
| commit | a32dc56d2e5447ef8988cb98b8686476cc94e70c (patch) | |
| tree | 61307503c4af82103cea2360fe95d3ea324968d6 /makima/src/bin | |
| parent | 73649d135efccda7e446775db773e21b458de202 (diff) | |
| download | soryu-a32dc56d2e5447ef8988cb98b8686476cc94e70c.tar.gz soryu-a32dc56d2e5447ef8988cb98b8686476cc94e70c.zip | |
Add Postgres for persistence and File cabinet
Migrations are local only currently, and must be run manually by setting POSTGRES_CONNECTION_URI
Diffstat (limited to 'makima/src/bin')
| -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 |
