Mountain/RPC/CocoonService/Task/
RegisterTaskProvider.rs1
2use serde_json::json;
7use tonic::{Response, Status};
8use CommonLibrary::LanguageFeature::DTO::ProviderType::ProviderType;
9
10use crate::{
11 ApplicationState::DTO::ProviderRegistrationDTO::ProviderRegistrationDTO,
12 RPC::CocoonService::CocoonServiceImpl,
13 Vine::Generated::{Empty, RegisterTaskProviderRequest},
14 dev_log,
15};
16
17pub async fn Fn(Service:&CocoonServiceImpl, Request:RegisterTaskProviderRequest) -> Result<Response<Empty>, Status> {
18 dev_log!("cocoon", "[CocoonService] Registering Task Provider: type={}", Request.r#type);
19
20 let Handle = Request
21 .r#type
22 .as_bytes()
23 .iter()
24 .fold(0u32, |Acc, B| Acc.wrapping_mul(31).wrapping_add(*B as u32));
25
26 let DTO = ProviderRegistrationDTO {
27 Handle,
28
29 ProviderType:ProviderType::Task,
30
31 Selector:json!([{ "language": "*" }]),
32
33 SideCarIdentifier:"cocoon-main".to_string(),
34
35 ExtensionIdentifier:json!(Request.extension_id),
36
37 Options:None,
38 };
39
40 Service
41 .environment
42 .ApplicationState
43 .Extension
44 .ProviderRegistration
45 .RegisterProvider(Handle, DTO);
46
47 Ok(Response::new(Empty {}))
48}