Skip to main content

Mountain/RPC/CocoonService/Initialization/
CancelOperation.rs

1//! Cancel an in-flight Mountain-originated operation by request id. Looks
2//! up the cancellation token in `Service.ActiveOperations` and fires it.
3
4use tonic::{Response, Status};
5use ::Vine::Generated::{CancelOperationRequest, Empty};
6
7use crate::{RPC::CocoonService::CocoonServiceImpl, dev_log};
8
9pub async fn Fn(Service:&CocoonServiceImpl, Request:CancelOperationRequest) -> Result<Response<Empty>, Status> {
10	dev_log!(
11		"cocoon",
12		"[CocoonService] Cancel operation request: {}",
13		Request.request_identifier_to_cancel
14	);
15
16	if let Some(Token) = Service.ActiveOperations.read().await.get(&Request.request_identifier_to_cancel) {
17		dev_log!(
18			"cocoon",
19			"[CocoonService] Triggering cancellation token for operation {}",
20			Request.request_identifier_to_cancel
21		);
22
23		Token.cancel();
24	} else {
25		dev_log!(
26			"cocoon",
27			"warn: [CocoonService] No active operation found for cancellation: {}",
28			Request.request_identifier_to_cancel
29		);
30	}
31
32	Ok(Response::new(Empty {}))
33}