-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.rs
More file actions
160 lines (142 loc) · 4.93 KB
/
mod.rs
File metadata and controls
160 lines (142 loc) · 4.93 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
use tucana::{
aquila::{
DataTypeUpdateRequest, FlowTypeUpdateRequest, RuntimeFunctionDefinitionUpdateRequest,
data_type_service_client::DataTypeServiceClient,
flow_type_service_client::FlowTypeServiceClient,
runtime_function_definition_service_client::RuntimeFunctionDefinitionServiceClient,
},
shared::{DataType, FlowType, RuntimeFunctionDefinition},
};
pub struct FlowUpdateService {
aquila_url: String,
data_types: Vec<DataType>,
runtime_definitions: Vec<RuntimeFunctionDefinition>,
flow_types: Vec<FlowType>,
}
impl FlowUpdateService {
pub fn from_url(aquila_url: String) -> Self {
Self {
aquila_url,
data_types: Vec::new(),
runtime_definitions: Vec::new(),
flow_types: Vec::new(),
}
}
pub fn with_flow_types(mut self, flow_types: Vec<FlowType>) -> Self {
self.flow_types = flow_types;
self
}
pub fn with_data_types(mut self, data_types: Vec<DataType>) -> Self {
self.data_types = data_types;
self
}
pub fn with_runtime_definitions(
mut self,
runtime_definitions: Vec<RuntimeFunctionDefinition>,
) -> Self {
self.runtime_definitions = runtime_definitions;
self
}
pub async fn send(&self) {
self.update_data_types().await;
self.update_runtime_definitions().await;
self.update_flow_types().await;
}
async fn update_data_types(&self) {
if self.data_types.is_empty() {
log::info!("No data types to update");
return;
}
log::info!("Updating the current DataTypes!");
let mut client = match DataTypeServiceClient::connect(self.aquila_url.clone()).await {
Ok(client) => {
log::info!("Successfully connected to the DataTypeService");
client
}
Err(err) => {
log::error!("Failed to connect to the DataTypeService: {:?}", err);
return;
}
};
let request = DataTypeUpdateRequest {
data_types: self.data_types.clone(),
};
match client.update(request).await {
Ok(response) => {
log::info!(
"Was the update of the DataTypes accepted by Sagittarius? {}",
response.into_inner().success
);
}
Err(err) => {
log::error!("Failed to update data types: {:?}", err);
}
}
}
async fn update_runtime_definitions(&self) {
if self.runtime_definitions.is_empty() {
log::info!("No runtime definitions to update");
return;
}
log::info!("Updating the current RuntimeDefinitions!");
let mut client =
match RuntimeFunctionDefinitionServiceClient::connect(self.aquila_url.clone()).await {
Ok(client) => {
log::info!("Connected to RuntimeFunctionDefinitionService");
client
}
Err(err) => {
log::error!(
"Failed to connect to RuntimeFunctionDefinitionService: {:?}",
err
);
return;
}
};
let request = RuntimeFunctionDefinitionUpdateRequest {
runtime_functions: self.runtime_definitions.clone(),
};
match client.update(request).await {
Ok(response) => {
log::info!(
"Was the update of the RuntimeFunctionDefinitions accepted by Sagittarius? {}",
response.into_inner().success
);
}
Err(err) => {
log::error!("Failed to update runtime function definitions: {:?}", err);
}
}
}
async fn update_flow_types(&self) {
if self.flow_types.is_empty() {
log::info!("No FlowTypes to update!");
return;
}
log::info!("Updating the current FlowTypes!");
let mut client = match FlowTypeServiceClient::connect(self.aquila_url.clone()).await {
Ok(client) => {
log::info!("Connected to FlowTypeService!");
client
}
Err(err) => {
log::error!("Failed to connect to FlowTypeService: {:?}", err);
return;
}
};
let request = FlowTypeUpdateRequest {
flow_types: self.flow_types.clone(),
};
match client.update(request).await {
Ok(response) => {
log::info!(
"Was the update of the FlowTypes accepted by Sagittarius? {}",
response.into_inner().success
);
}
Err(err) => {
log::error!("Failed to update flow types: {:?}", err);
}
}
}
}