Skip to content
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

Chariott usage cleanup #31

Merged
merged 1 commit into from
Jun 13, 2023
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
20 changes: 14 additions & 6 deletions core/invehicle-digital-twin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use core_protobuf_data_access::chariott::runtime::v1::{
};
use core_protobuf_data_access::digital_twin::v1::digital_twin_server::DigitalTwinServer;
use env_logger::{Builder, Target};
use log::{debug, info, LevelFilter};
use log::{debug, error, info, LevelFilter};
use parking_lot::RwLock;
use std::collections::HashMap;
use std::net::SocketAddr;
Expand Down Expand Up @@ -54,13 +54,11 @@ pub async fn register_digital_twin_service_with_chariott(

let request = Request::new(RegisterRequest { service, intents });

let response = client
let _response = client
.register(request)
.await
.map_err(|_| Status::internal("Chariott register request failed"))?;

info!("{:?}", response.into_inner());

Ok(())
}

Expand Down Expand Up @@ -96,11 +94,21 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// after 15 seconds unless the CHARIOTT_REGISTRY_TTL_SECS environment variable is set. Please make sure that
// it is set (and exported) in the shell running Chariott before Chariott has started.
if chariott_url_option.is_some() {
register_digital_twin_service_with_chariott(
match register_digital_twin_service_with_chariott(
&chariott_url_option.unwrap(),
&invehicle_digital_twin_address,
)
.await?;
.await
{
Ok(()) => return Ok(()),
Err(error) => {
error!("Failed to register this service with Chariott: '{error}'");
Err(error)?
}
};
info!("This service is now registered with Chariott.");
} else {
info!("This service is not using Chariott.");
}

server_future.await?;
Expand Down
6 changes: 5 additions & 1 deletion samples/common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,14 @@ pub async fn retrieve_invehicle_digital_twin_url(
// First try to use the one specified in the invehicle_digital_twin_url setting.
// If it is not set, then go to Chariott to obtain it.
let result = match invehicle_digital_twin_url {
Some(value) => value,
Some(value) => {
info!("The URL for the in-vehicle digital twin service is specified in the settings file.");
value
},
None => {
match chariott_url {
Some(value) => {
info!("The URL for the in-vehicle digital twin service will be retrieved from Chariott.");
match retry_async_based_on_status(30, Duration::from_secs(1), || discover_digital_twin_service_using_chariott(&value)).await {
Ok(value) => value,
Err(error) => Err(format!("Failed to discover the in-vehicle digital twin service's URL due to error: {error}"))?
Expand Down