-
Notifications
You must be signed in to change notification settings - Fork 0
Implement RuntimeStatusService #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+220
−42
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b999fd3
fix: expected a struct for headers instead of a list value
raphael-goetz b15e87e
feat: started to work on runtime status service
raphael-goetz cd4c197
feat: configured adapter configs for rest and cron
raphael-goetz 333eaf6
feat: added update for runtime status service to runner
raphael-goetz d9aa22c
ref: cargo clippy
raphael-goetz b9ea78a
ref: cargo fmt
raphael-goetz b8e2ae5
Potential fix for pull request finding
raphael-goetz 9b25797
Potential fix for pull request finding
raphael-goetz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| use std::time::{SystemTime, UNIX_EPOCH}; | ||
|
|
||
| use tokio::time::sleep; | ||
| use tonic::transport::{Channel, Endpoint}; | ||
| use tucana::{ | ||
| aquila::{ | ||
| RuntimeStatusUpdateRequest, runtime_status_service_client::RuntimeStatusServiceClient, | ||
| runtime_status_update_request::Status, | ||
| }, | ||
| shared::{AdapterConfiguration, AdapterRuntimeStatus, RuntimeFeature}, | ||
| }; | ||
|
|
||
| pub struct DracoRuntimeStatusService { | ||
| channel: Channel, | ||
| identifier: String, | ||
| features: Vec<RuntimeFeature>, | ||
| configs: Vec<AdapterConfiguration>, | ||
| } | ||
|
|
||
| const MAX_BACKOFF: u64 = 2000 * 60; | ||
| const MAX_RETRIES: i8 = 10; | ||
|
|
||
| // Will create a channel and retry if its not possible | ||
| pub async fn create_channel_with_retry(channel_name: &str, url: String) -> Channel { | ||
| let mut backoff = 100; | ||
| let mut retries = 0; | ||
|
|
||
| loop { | ||
| let channel = match Endpoint::from_shared(url.clone()) { | ||
| Ok(c) => { | ||
| log::debug!("Creating a new endpoint for the: {} Service", channel_name); | ||
| c.connect_timeout(std::time::Duration::from_secs(2)) | ||
| .timeout(std::time::Duration::from_secs(10)) | ||
| } | ||
| Err(err) => { | ||
| panic!( | ||
| "Cannot create Endpoint for Service: `{}`. Reason: {:?}", | ||
| channel_name, err | ||
| ); | ||
| } | ||
| }; | ||
|
|
||
| match channel.connect().await { | ||
| Ok(ch) => { | ||
| return ch; | ||
| } | ||
| Err(err) => { | ||
| log::warn!( | ||
| "Retry connect to `{}` using url: `{}` failed: {:?}, retrying in {}ms", | ||
| channel_name, | ||
| url, | ||
| err, | ||
| backoff | ||
| ); | ||
| sleep(std::time::Duration::from_millis(backoff)).await; | ||
|
|
||
| backoff = (backoff * 2).min(MAX_BACKOFF); | ||
| retries += 1; | ||
|
|
||
| if retries >= MAX_RETRIES { | ||
| panic!("Reached max retries to url {}", url) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| impl DracoRuntimeStatusService { | ||
| pub async fn from_url( | ||
| aquila_url: String, | ||
| identifier: String, | ||
| features: Vec<RuntimeFeature>, | ||
| configs: Vec<AdapterConfiguration>, | ||
| ) -> Self { | ||
| let channel = create_channel_with_retry("Aquila", aquila_url).await; | ||
| Self::new(channel, identifier, features, configs) | ||
| } | ||
|
|
||
| pub fn new( | ||
| channel: Channel, | ||
| identifier: String, | ||
| features: Vec<RuntimeFeature>, | ||
| configs: Vec<AdapterConfiguration>, | ||
| ) -> Self { | ||
| DracoRuntimeStatusService { | ||
| channel, | ||
| identifier, | ||
| features, | ||
| configs, | ||
| } | ||
| } | ||
|
|
||
| pub async fn update_runtime_status_by_status( | ||
| &self, | ||
| status: tucana::shared::adapter_runtime_status::Status, | ||
| ) { | ||
| log::info!("Updating the current Runtime Status!"); | ||
| let mut client = RuntimeStatusServiceClient::new(self.channel.clone()); | ||
|
|
||
| let now = SystemTime::now(); | ||
| let timestamp = match now.duration_since(UNIX_EPOCH) { | ||
| Ok(time) => time.as_secs(), | ||
| Err(err) => { | ||
| log::error!("cannot get current system time: {:?}", err); | ||
| 0 | ||
| } | ||
| }; | ||
|
|
||
| let request = RuntimeStatusUpdateRequest { | ||
| status: Some(Status::AdapterRuntimeStatus(AdapterRuntimeStatus { | ||
| status: status.into(), | ||
| timestamp: timestamp as i64, | ||
| identifier: self.identifier.clone(), | ||
| features: self.features.clone(), | ||
| configurations: self.configs.clone(), | ||
| })), | ||
| }; | ||
|
|
||
| match client.update(request).await { | ||
| Ok(response) => { | ||
| log::info!( | ||
| "Was the update of the RuntimeStatus accepted by Sagittarius? {}", | ||
| response.into_inner().success | ||
| ); | ||
| } | ||
| Err(err) => { | ||
| log::error!("Failed to update RuntimeStatus: {:?}", err); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| pub mod client; | ||
| pub mod config; | ||
| pub mod runner; | ||
| pub mod store; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.