-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_client_impl.rs
More file actions
56 lines (51 loc) · 1.99 KB
/
function_client_impl.rs
File metadata and controls
56 lines (51 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use crate::command::push::auth::get_authorization_metadata;
use crate::formatter::error_without_trace;
use crate::formatter::info;
use tonic::Extensions;
use tonic::Request;
use tonic::transport::Channel;
use tucana::sagittarius::RuntimeFunctionDefinitionUpdateRequest as SagittariusRuntimeFunctionUpdateRequest;
use tucana::sagittarius::runtime_function_definition_service_client::RuntimeFunctionDefinitionServiceClient;
use tucana::shared::RuntimeFunctionDefinition;
pub struct SagittariusRuntimeFunctionServiceClient {
client: RuntimeFunctionDefinitionServiceClient<Channel>,
token: String,
}
impl SagittariusRuntimeFunctionServiceClient {
pub async fn new(sagittarius_url: String, token: String) -> Self {
let client = match RuntimeFunctionDefinitionServiceClient::connect(sagittarius_url).await {
Ok(client) => {
info(String::from(
"Successfully connected to Sagittarius RuntimeFunction Endpoint!",
));
client
}
Err(err) => panic!(
"Failed to connect to Sagittarius (RuntimeFunction Endpoint): {:?}",
err
),
};
Self { client, token }
}
pub async fn update_runtime_function_definitions(
&mut self,
runtime_functions: Vec<RuntimeFunctionDefinition>,
) {
let request = Request::from_parts(
get_authorization_metadata(&self.token),
Extensions::new(),
SagittariusRuntimeFunctionUpdateRequest { runtime_functions },
);
match self.client.update(request).await {
Ok(response) => {
info(format!(
"Successfully transferred RuntimeFunctions. Did Sagittarius updated them? {:?}",
&response.into_inner().success
));
}
Err(err) => {
error_without_trace(format!("Failed to update RuntimeFunctions: {:?}", err));
}
};
}
}