Start sync client manager implementation

This commit is contained in:
2025-02-12 21:01:34 +01:00
parent 17e086b43c
commit 3822c209d3
6 changed files with 47 additions and 12 deletions

View File

@ -1,3 +1,4 @@
use crate::broadcast_messages::BroadcastMessage;
use crate::constants::{WS_CLIENT_TIMEOUT, WS_HEARTBEAT_INTERVAL};
use crate::extractors::client_auth::APIClientAuth;
use crate::server::HttpResult;
@ -10,9 +11,6 @@ use tokio::select;
use tokio::sync::broadcast;
use tokio::sync::broadcast::Receiver;
use tokio::time::interval;
use crate::broadcast_messages::BroadcastMessage;
/// Main WS route
pub async fn ws(
@ -25,6 +23,13 @@ pub async fn ws(
let (res, session, msg_stream) = actix_ws::handle(&req, stream)?;
// Ask for sync client to be started
if let Err(e) = tx.send(BroadcastMessage::StartSyncTaskForUser(
auth.user.user_id.clone(),
)) {
log::error!("Failed to send StartSyncTaskForUser: {}", e);
}
let rx = tx.subscribe();
// spawn websocket handler (and don't await it) so that the response is returned immediately