Can request sync thread stop
This commit is contained in:
@@ -20,3 +20,20 @@ pub async fn start_sync(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Stop sync thread
|
||||
pub async fn stop_sync(
|
||||
client: MatrixClientExtractor,
|
||||
manager: web::Data<ActorRef<MatrixManagerMsg>>,
|
||||
) -> 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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)?
|
||||
|
||||
@@ -15,6 +15,7 @@ pub enum MatrixManagerMsg {
|
||||
GetClient(UserEmail, RpcReplyPort<anyhow::Result<MatrixClient>>),
|
||||
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!(
|
||||
|
||||
Reference in New Issue
Block a user