Mountain/RPC/CocoonService/Initialization/
CancelOperation.rs1
2use tonic::{Response, Status};
6
7use crate::{
8 RPC::CocoonService::CocoonServiceImpl,
9 Vine::Generated::{CancelOperationRequest, Empty},
10 dev_log,
11};
12
13pub async fn Fn(Service:&CocoonServiceImpl, Request:CancelOperationRequest) -> Result<Response<Empty>, Status> {
14 dev_log!(
15 "cocoon",
16 "[CocoonService] Cancel operation request: {}",
17 Request.request_identifier_to_cancel
18 );
19
20 if let Some(Token) = Service.ActiveOperations.read().await.get(&Request.request_identifier_to_cancel) {
21 dev_log!(
22 "cocoon",
23 "[CocoonService] Triggering cancellation token for operation {}",
24 Request.request_identifier_to_cancel
25 );
26
27 Token.cancel();
28 } else {
29 dev_log!(
30 "cocoon",
31 "warn: [CocoonService] No active operation found for cancellation: {}",
32 Request.request_identifier_to_cancel
33 );
34 }
35
36 Ok(Response::new(Empty {}))
37}