Skip to content

Commit b8fb7d5

Browse files
Merge pull request #124 from code0-tech/#95-runtime-status-service
Add RuntimeStatusService
2 parents 5fbebb5 + 39498d1 commit b8fb7d5

3 files changed

Lines changed: 106 additions & 1 deletion

File tree

crates/taurus/src/client/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod runtime_status;
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
use std::time::{SystemTime, UNIX_EPOCH};
2+
3+
use code0_flow::flow_service::retry::create_channel_with_retry;
4+
use tonic::transport::Channel;
5+
use tucana::{
6+
aquila::{
7+
RuntimeStatusUpdateRequest, runtime_status_service_client::RuntimeStatusServiceClient,
8+
runtime_status_update_request::Status,
9+
},
10+
shared::{ExecutionRuntimeStatus, RuntimeFeature},
11+
};
12+
13+
pub struct TaurusRuntimeStatusService {
14+
channel: Channel,
15+
identifier: String,
16+
features: Vec<RuntimeFeature>,
17+
}
18+
19+
impl TaurusRuntimeStatusService {
20+
pub async fn from_url(
21+
aquila_url: String,
22+
identifier: String,
23+
features: Vec<RuntimeFeature>,
24+
) -> Self {
25+
let channel = create_channel_with_retry("Aquila", aquila_url).await;
26+
Self::new(channel, identifier, features)
27+
}
28+
29+
pub fn new(channel: Channel, identifier: String, features: Vec<RuntimeFeature>) -> Self {
30+
TaurusRuntimeStatusService {
31+
channel,
32+
identifier,
33+
features,
34+
}
35+
}
36+
37+
pub async fn update_runtime_status(
38+
&self,
39+
status: tucana::shared::execution_runtime_status::Status,
40+
) {
41+
log::info!("Updating the current Runtime Status!");
42+
let mut client = RuntimeStatusServiceClient::new(self.channel.clone());
43+
44+
let now = SystemTime::now();
45+
let timestamp = match now.duration_since(UNIX_EPOCH) {
46+
Ok(time) => time.as_secs(),
47+
Err(err) => {
48+
log::error!("cannot get current system time: {:?}", err);
49+
0
50+
}
51+
};
52+
53+
let request = RuntimeStatusUpdateRequest {
54+
status: Some(Status::ExecutionRuntimeStatus(ExecutionRuntimeStatus {
55+
status: status.into(),
56+
timestamp: timestamp as i64,
57+
identifier: self.identifier.clone(),
58+
features: self.features.clone(),
59+
})),
60+
};
61+
62+
match client.update(request).await {
63+
Ok(response) => {
64+
log::info!(
65+
"Was the update of the RuntimeStatus accepted by Sagittarius? {}",
66+
response.into_inner().success
67+
);
68+
}
69+
Err(err) => {
70+
log::error!("Failed to update RuntimeStatus: {:?}", err);
71+
}
72+
}
73+
}
74+
}

crates/taurus/src/main.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
mod client;
12
mod config;
23

4+
use crate::client::runtime_status::TaurusRuntimeStatusService;
35
use crate::config::Config;
46
use code0_flow::flow_service::FlowUpdateService;
57

@@ -16,7 +18,7 @@ use taurus_core::context::signal::Signal;
1618
use tokio::signal;
1719
use tonic_health::pb::health_server::HealthServer;
1820
use tucana::shared::value::Kind;
19-
use tucana::shared::{ExecutionFlow, NodeFunction, Value};
21+
use tucana::shared::{ExecutionFlow, NodeFunction, RuntimeFeature, Translation, Value};
2022

2123
fn handle_message(flow: ExecutionFlow, store: &FunctionStore) -> Signal {
2224
let mut context = Context::default();
@@ -40,6 +42,7 @@ async fn main() {
4042

4143
let config = Config::new();
4244
let store = FunctionStore::default();
45+
let mut runtime_status_service: Option<TaurusRuntimeStatusService> = None;
4346

4447
let client = match async_nats::connect(config.nats_url.clone()).await {
4548
Ok(client) => {
@@ -88,6 +91,27 @@ async fn main() {
8891
.await
8992
.send()
9093
.await;
94+
95+
let status_service = TaurusRuntimeStatusService::from_url(
96+
config.aquila_url.clone(),
97+
"taurus".into(),
98+
vec![RuntimeFeature {
99+
name: vec![Translation {
100+
code: "en-US".to_string(),
101+
content: "Runtime".to_string(),
102+
}],
103+
description: vec![Translation {
104+
code: "en-US".to_string(),
105+
content: "Will execute incoming flows.".to_string(),
106+
}],
107+
}],
108+
)
109+
.await;
110+
111+
status_service
112+
.update_runtime_status(tucana::shared::execution_runtime_status::Status::Running)
113+
.await;
114+
runtime_status_service = Some(status_service);
91115
}
92116

93117
let mut worker_task = tokio::spawn(async move {
@@ -212,5 +236,11 @@ async fn main() {
212236
}
213237
}
214238

239+
if let Some(status_service) = &runtime_status_service {
240+
status_service
241+
.update_runtime_status(tucana::shared::execution_runtime_status::Status::Stopped)
242+
.await;
243+
};
244+
215245
log::info!("Taurus shutdown complete");
216246
}

0 commit comments

Comments
 (0)