Skip to main content

Mountain/RPC/CocoonService/Task/
RegisterTaskProvider.rs

1#![allow(non_snake_case)]
2
3//! Register a Cocoon-contributed task provider in `ApplicationState`. The
4//! gRPC proto carries no handle, so we hash the task `type` string for
5//! the registration handle.
6
7use serde_json::json;
8use tonic::{Response, Status};
9use CommonLibrary::LanguageFeature::DTO::ProviderType::ProviderType;
10
11use crate::{
12	ApplicationState::DTO::ProviderRegistrationDTO::ProviderRegistrationDTO,
13	RPC::CocoonService::CocoonServiceImpl,
14	Vine::Generated::{Empty, RegisterTaskProviderRequest},
15	dev_log,
16};
17
18pub async fn Fn(Service:&CocoonServiceImpl, Request:RegisterTaskProviderRequest) -> Result<Response<Empty>, Status> {
19	dev_log!("cocoon", "[CocoonService] Registering Task Provider: type={}", Request.r#type);
20
21	let Handle = Request
22		.r#type
23		.as_bytes()
24		.iter()
25		.fold(0u32, |Acc, B| Acc.wrapping_mul(31).wrapping_add(*B as u32));
26
27	let DTO = ProviderRegistrationDTO {
28		Handle,
29
30		ProviderType:ProviderType::Task,
31
32		Selector:json!([{ "language": "*" }]),
33
34		SideCarIdentifier:"cocoon-main".to_string(),
35
36		ExtensionIdentifier:json!(Request.extension_id),
37
38		Options:None,
39	};
40
41	Service
42		.environment
43		.ApplicationState
44		.Extension
45		.ProviderRegistration
46		.RegisterProvider(Handle, DTO);
47
48	Ok(Response::new(Empty {}))
49}