summaryrefslogtreecommitdiff
path: root/makima/src/server/state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'makima/src/server/state.rs')
-rw-r--r--makima/src/server/state.rs30
1 files changed, 29 insertions, 1 deletions
diff --git a/makima/src/server/state.rs b/makima/src/server/state.rs
index 8cdc26c..239ab77 100644
--- a/makima/src/server/state.rs
+++ b/makima/src/server/state.rs
@@ -2,10 +2,24 @@
use std::sync::Arc;
use sqlx::PgPool;
-use tokio::sync::Mutex;
+use tokio::sync::{broadcast, Mutex};
+use uuid::Uuid;
use crate::listen::{DiarizationConfig, ParakeetEOU, ParakeetTDT, Sortformer};
+/// Notification payload for file updates (broadcast to WebSocket subscribers).
+#[derive(Debug, Clone)]
+pub struct FileUpdateNotification {
+ /// ID of the updated file
+ pub file_id: Uuid,
+ /// New version number after update
+ pub version: i32,
+ /// List of fields that were updated
+ pub updated_fields: Vec<String>,
+ /// Source of the update: "user", "llm", or "system"
+ pub updated_by: String,
+}
+
/// Shared application state containing ML models and database pool.
///
/// Models are wrapped in `Mutex` for thread-safe mutable access during inference.
@@ -18,6 +32,8 @@ pub struct AppState {
pub sortformer: Mutex<Sortformer>,
/// Optional database connection pool
pub db_pool: Option<PgPool>,
+ /// Broadcast channel for file update notifications
+ pub file_updates: broadcast::Sender<FileUpdateNotification>,
}
impl AppState {
@@ -40,11 +56,15 @@ impl AppState {
DiarizationConfig::callhome(),
)?;
+ // Create broadcast channel with buffer for 256 messages
+ let (file_updates, _) = broadcast::channel(256);
+
Ok(Self {
parakeet: Mutex::new(parakeet),
parakeet_eou: Mutex::new(parakeet_eou),
sortformer: Mutex::new(sortformer),
db_pool: None,
+ file_updates,
})
}
@@ -53,6 +73,14 @@ impl AppState {
self.db_pool = Some(pool);
self
}
+
+ /// Broadcast a file update notification to all subscribers.
+ ///
+ /// This is a no-op if there are no subscribers (ignores send errors).
+ pub fn broadcast_file_update(&self, notification: FileUpdateNotification) {
+ // Ignore send errors - they just mean no one is listening
+ let _ = self.file_updates.send(notification);
+ }
}
/// Type alias for the shared application state.