Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions crates/taurus/src/client/runtime_status.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::time::{SystemTime, UNIX_EPOCH};

use code0_flow::flow_service::retry::create_channel_with_retry;
use tonic::transport::Channel;
use code0_flow::flow_service::{
auth::get_authorization_metadata, retry::create_channel_with_retry,
};
use tonic::{Extensions, Request, transport::Channel};
use tucana::{
aquila::{
RuntimeStatusUpdateRequest, runtime_status_service_client::RuntimeStatusServiceClient,
Expand All @@ -14,23 +16,31 @@ pub struct TaurusRuntimeStatusService {
channel: Channel,
identifier: String,
features: Vec<RuntimeFeature>,
aquila_token: String,
}

impl TaurusRuntimeStatusService {
pub async fn from_url(
aquila_url: String,
aquila_token: String,
identifier: String,
features: Vec<RuntimeFeature>,
) -> Self {
let channel = create_channel_with_retry("Aquila", aquila_url).await;
Self::new(channel, identifier, features)
Self::new(channel, aquila_token, identifier, features)
}

pub fn new(channel: Channel, identifier: String, features: Vec<RuntimeFeature>) -> Self {
pub fn new(
channel: Channel,
aquila_token: String,
identifier: String,
features: Vec<RuntimeFeature>,
) -> Self {
TaurusRuntimeStatusService {
channel,
identifier,
features,
aquila_token,
}
}

Expand All @@ -50,14 +60,18 @@ impl TaurusRuntimeStatusService {
}
};

let request = RuntimeStatusUpdateRequest {
status: Some(Status::ExecutionRuntimeStatus(ExecutionRuntimeStatus {
status: status.into(),
timestamp: timestamp as i64,
identifier: self.identifier.clone(),
features: self.features.clone(),
})),
};
let request = Request::from_parts(
get_authorization_metadata(&self.aquila_token),
Extensions::new(),
RuntimeStatusUpdateRequest {
status: Some(Status::ExecutionRuntimeStatus(ExecutionRuntimeStatus {
status: status.into(),
timestamp: timestamp as i64,
identifier: self.identifier.clone(),
features: self.features.clone(),
})),
},
);

match client.update(request).await {
Ok(response) => {
Expand Down
30 changes: 20 additions & 10 deletions crates/taurus/src/client/runtime_usage.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,47 @@
use code0_flow::flow_service::retry::create_channel_with_retry;
use tonic::transport::Channel;
use code0_flow::flow_service::{
auth::get_authorization_metadata, retry::create_channel_with_retry,
};
use tonic::{Extensions, Request, transport::Channel};
use tucana::{
aquila::{RuntimeUsageRequest, runtime_usage_service_client::RuntimeUsageServiceClient},
shared::RuntimeUsage,
};

pub struct TaurusRuntimeUsageService {
channel: Channel,
aquila_token: String,
}

impl TaurusRuntimeUsageService {
pub async fn from_url(aquila_url: String) -> Self {
pub async fn from_url(aquila_url: String, aquila_token: String) -> Self {
let channel = create_channel_with_retry("Aquila", aquila_url).await;
TaurusRuntimeUsageService { channel }
TaurusRuntimeUsageService {
channel,
aquila_token,
}
}

pub async fn update_runtime_usage(&self, runtime_usage: RuntimeUsage) {
log::info!("Updating the current Runtime Status!");
log::info!("Updating the current Runtime Usage!");
let mut client = RuntimeUsageServiceClient::new(self.channel.clone());

let request = RuntimeUsageRequest {
runtime_usage: vec![runtime_usage],
};
let request = Request::from_parts(
get_authorization_metadata(&self.aquila_token),
Extensions::new(),
RuntimeUsageRequest {
runtime_usage: vec![runtime_usage],
},
);

match client.update(request).await {
Ok(response) => {
log::info!(
"Was the update of the RuntimeStatus accepted by Sagittarius? {}",
"Was the update of the RuntimeUsage accepted by Sagittarius? {}",
response.into_inner().success
);
}
Err(err) => {
log::error!("Failed to update RuntimeStatus: {:?}", err);
log::error!("Failed to update RuntimeUsage: {:?}", err);
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion crates/taurus/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,16 @@ async fn main() {
.send()
.await;

let usage_service = TaurusRuntimeUsageService::from_url(config.aquila_url.clone()).await;
let usage_service = TaurusRuntimeUsageService::from_url(
config.aquila_url.clone(),
config.aquila_token.clone(),
)
.await;
runtime_usage_service = Some(usage_service);

let status_service = TaurusRuntimeStatusService::from_url(
config.aquila_url.clone(),
config.aquila_token.clone(),
"taurus".into(),
vec![RuntimeFeature {
name: vec![Translation {
Expand Down