Skip to content

Commit b15e87e

Browse files
committed
feat: started to work on runtime status service
1 parent b999fd3 commit b15e87e

2 files changed

Lines changed: 97 additions & 0 deletions

File tree

crates/base/src/client/mod.rs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
use std::time::{SystemTime, UNIX_EPOCH};
2+
3+
use tonic::transport::Channel;
4+
use tucana::{
5+
aquila::{
6+
RuntimeStatusUpdateRequest, runtime_status_service_client::RuntimeStatusServiceClient,
7+
runtime_status_update_request::Status,
8+
},
9+
shared::{AdapterConfiguration, AdapterRuntimeStatus, RuntimeFeature},
10+
};
11+
12+
struct DracoRuntimeStatusService {
13+
channel: Channel,
14+
identifier: String,
15+
features: Vec<RuntimeFeature>,
16+
configs: Vec<AdapterConfiguration>,
17+
}
18+
19+
impl DracoRuntimeStatusService {
20+
fn new(
21+
channel: Channel,
22+
identifier: String,
23+
features: Vec<RuntimeFeature>,
24+
configs: Vec<AdapterConfiguration>,
25+
) -> Self {
26+
DracoRuntimeStatusService {
27+
channel,
28+
identifier,
29+
features,
30+
configs,
31+
}
32+
}
33+
34+
async fn add_config(&mut self, feat: RuntimeFeature) {
35+
self.features.push(feat);
36+
}
37+
38+
async fn update_runtime_status_by_status(
39+
&self,
40+
status: tucana::shared::adapter_runtime_status::Status,
41+
) {
42+
log::info!("Updating the current Runtime Status!");
43+
let mut client = RuntimeStatusServiceClient::new(self.channel.clone());
44+
45+
let now = SystemTime::now();
46+
let timestamp = match now.duration_since(UNIX_EPOCH) {
47+
Ok(time) => time.as_secs(),
48+
Err(err) => {
49+
log::error!("cannot get current system time: {:?}", err);
50+
0
51+
}
52+
};
53+
54+
let request = RuntimeStatusUpdateRequest {
55+
status: Some(Status::AdapterRuntimeStatus(AdapterRuntimeStatus {
56+
status: status.into(),
57+
timestamp: timestamp as i64,
58+
identifier: self.identifier.clone(),
59+
features: self.features.clone(),
60+
configurations: self.configs.clone(),
61+
})),
62+
};
63+
64+
match client.update(request).await {
65+
Ok(response) => {
66+
log::info!(
67+
"Was the update of the RuntimeStatus accepted by Sagittarius? {}",
68+
response.into_inner().success
69+
);
70+
}
71+
Err(err) => {
72+
log::error!("Failed to update RuntimeStatus: {:?}", err);
73+
}
74+
}
75+
}
76+
async fn update_runtime_status(&self, status: AdapterRuntimeStatus) {
77+
log::info!("Updating the current Runtime Status!");
78+
let mut client = RuntimeStatusServiceClient::new(self.channel.clone());
79+
80+
let request = RuntimeStatusUpdateRequest {
81+
status: Some(Status::AdapterRuntimeStatus(status)),
82+
};
83+
84+
match client.update(request).await {
85+
Ok(response) => {
86+
log::info!(
87+
"Was the update of the RuntimeStatus accepted by Sagittarius? {}",
88+
response.into_inner().success
89+
);
90+
}
91+
Err(err) => {
92+
log::error!("Failed to update RuntimeStatus: {:?}", err);
93+
}
94+
}
95+
}
96+
}

crates/base/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod client;
12
pub mod config;
23
pub mod runner;
34
pub mod store;

0 commit comments

Comments
 (0)