From 1e00d24a8beab558373ebf41fc8f87172236a005 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 19 Nov 2025 15:51:15 +0100 Subject: [PATCH] Can request sync thread stop --- .../matrix_sync_thread_controller.rs | 17 +++++++++++++++++ matrixgw_backend/src/main.rs | 4 ++++ .../src/matrix_connection/matrix_manager.rs | 10 ++++++++++ 3 files changed, 31 insertions(+) diff --git a/matrixgw_backend/src/controllers/matrix_sync_thread_controller.rs b/matrixgw_backend/src/controllers/matrix_sync_thread_controller.rs index bbfa799..ee76bfc 100644 --- a/matrixgw_backend/src/controllers/matrix_sync_thread_controller.rs +++ b/matrixgw_backend/src/controllers/matrix_sync_thread_controller.rs @@ -20,3 +20,20 @@ pub async fn start_sync( } } } + +/// Stop sync thread +pub async fn stop_sync( + client: MatrixClientExtractor, + manager: web::Data>, +) -> HttpResult { + match ractor::cast!( + manager, + MatrixManagerMsg::StopSyncThread(client.auth.user.email.clone()) + ) { + Ok(_) => Ok(HttpResponse::Accepted().finish()), + Err(e) => { + log::error!("Failed to stop sync thread: {e}"); + Ok(HttpResponse::InternalServerError().finish()) + } + } +} diff --git a/matrixgw_backend/src/main.rs b/matrixgw_backend/src/main.rs index 9a98eb9..72e98d9 100644 --- a/matrixgw_backend/src/main.rs +++ b/matrixgw_backend/src/main.rs @@ -125,6 +125,10 @@ async fn main() -> std::io::Result<()> { "/api/matrix_sync/start", web::post().to(matrix_sync_thread_controller::start_sync), ) + .route( + "/api/matrix_sync/stop", + web::post().to(matrix_sync_thread_controller::stop_sync), + ) }) .workers(4) .bind(&AppConfig::get().listen_address)? diff --git a/matrixgw_backend/src/matrix_connection/matrix_manager.rs b/matrixgw_backend/src/matrix_connection/matrix_manager.rs index c7a3ccb..da25d39 100644 --- a/matrixgw_backend/src/matrix_connection/matrix_manager.rs +++ b/matrixgw_backend/src/matrix_connection/matrix_manager.rs @@ -15,6 +15,7 @@ pub enum MatrixManagerMsg { GetClient(UserEmail, RpcReplyPort>), DisconnectClient(UserEmail), StartSyncThread(UserEmail), + StopSyncThread(UserEmail), SyncThreadTerminated(UserEmail, MatrixSyncTaskID), } @@ -117,6 +118,15 @@ impl Actor for MatrixManagerActor { .await?; state.running_sync_threads.insert(email, thread_id); } + MatrixManagerMsg::StopSyncThread(email) => { + if let Some(thread_id) = state.running_sync_threads.get(&email) + && let Err(e) = state + .broadcast_sender + .send(BroadcastMessage::StopSyncThread(thread_id.clone())) + { + log::error!("Failed to request sync thread stop: {e}"); + } + } MatrixManagerMsg::SyncThreadTerminated(email, task_id) => { if state.running_sync_threads.get(&email) == Some(&task_id) { log::info!(