summaryrefslogtreecommitdiff
path: root/makima/src/bin/server.rs
diff options
context:
space:
mode:
authorsoryu <soryu@soryu.co>2025-12-23 02:14:58 +0000
committersoryu <soryu@soryu.co>2025-12-23 14:47:18 +0000
commita32dc56d2e5447ef8988cb98b8686476cc94e70c (patch)
tree61307503c4af82103cea2360fe95d3ea324968d6 /makima/src/bin/server.rs
parent73649d135efccda7e446775db773e21b458de202 (diff)
downloadsoryu-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/server.rs')
-rw-r--r--makima/src/bin/server.rs26
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(&parakeet_dir, &parakeet_eou_dir, &sortformer_path)
- .map_err(|e| anyhow::anyhow!("Failed to load models: {}", e))?,
- );
+ let mut app_state = AppState::new(&parakeet_dir, &parakeet_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