Skip to main content

Mountain/RPC/CocoonService/Initialization/
CancelOperation.rs

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