Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
wilyle committed Feb 16, 2024
1 parent 935aa1e commit 1a56c0e
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ use tokio::sync::Mutex;
use crate::config::Config;
use freyja_build_common::config_file_stem;
use freyja_common::{
config_utils, out_dir,
config_utils,
digital_twin_adapter::{
DigitalTwinAdapter, DigitalTwinAdapterError, DigitalTwinAdapterErrorKind, FindByIdRequest,
FindByIdResponse,
},
out_dir,
service_discovery_adapter_selector::ServiceDiscoveryAdapterSelector,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ use tokio::sync::Mutex;
use crate::config::Config;
use freyja_build_common::config_file_stem;
use freyja_common::{
config_utils, out_dir,
config_utils,
digital_twin_adapter::{
DigitalTwinAdapter, DigitalTwinAdapterError, FindByIdRequest, FindByIdResponse,
},
out_dir,
service_discovery_adapter_selector::ServiceDiscoveryAdapterSelector,
};
use mock_digital_twin::ENTITY_QUERY_PATH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ impl ServiceDiscoveryAdapter for ChariottServiceDiscoveryAdapter {
})?
.uri;
Ok(Ok(uri))
},
}
// This branch returns Ok(Err(_)) to indicate to the execute_with_retry wrapper that processing should stop
Err(status) if status.code() == Code::NotFound => Ok(Err(ServiceDiscoveryAdapterError::not_found(status))),
Err(status) if status.code() == Code::NotFound => {
Ok(Err(ServiceDiscoveryAdapterError::not_found(status)))
}
// This branch returns Err(_) to indicate to the execute_with_retry wrapper that the request should be retried
Err(e) => Err(ServiceDiscoveryAdapterError::communication(e)),
}
Expand Down
2 changes: 1 addition & 1 deletion common/src/digital_twin_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{entity::Entity, service_discovery_adapter_selector::ServiceDiscovery
#[async_trait]
pub trait DigitalTwinAdapter {
/// Creates a new instance of a DigitalTwinAdapter with default settings
///
///
/// # Arguments
/// - `selector`: the service dicovery adapter selector to use
fn create_new(
Expand Down
2 changes: 1 addition & 1 deletion common/src/service_discovery_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub trait ServiceDiscoveryAdapter {
fn create_new() -> Result<Self, ServiceDiscoveryAdapterError>
where
Self: Sized;

/// Gets the name of this adapter. Used for diagnostic purposes.
fn get_adapter_name(&self) -> String;

Expand Down
2 changes: 1 addition & 1 deletion common/src/service_discovery_adapter_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::service_discovery_adapter::{ServiceDiscoveryAdapter, ServiceDiscovery
#[async_trait]
pub trait ServiceDiscoveryAdapterSelector {
/// Registers a `ServiceDiscoveryAdapter` with this selector
///
///
/// # Arguments
/// - `adapter`: the adapter to register
fn register(
Expand Down
7 changes: 3 additions & 4 deletions freyja/examples/in-memory-with-fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
),
];

let service_discovery_adapters: Vec<Box<dyn ServiceDiscoveryAdapter + Send + Sync>> = vec![
Box::new(
let service_discovery_adapters: Vec<Box<dyn ServiceDiscoveryAdapter + Send + Sync>> =
vec![Box::new(
FileServiceDiscoveryAdapter::create_new()
.expect("Could not create FileServiceDiscoveryAdapter"),
),
];
)];

freyja::freyja_main::<
InMemoryMockDigitalTwinAdapter,
Expand Down
2 changes: 1 addition & 1 deletion freyja/examples/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ freyja::freyja_main! {
MockMappingServiceAdapter,
[HttpMockDataAdapterFactory],
[FileServiceDiscoveryAdapter],
}
}
15 changes: 10 additions & 5 deletions freyja/src/service_discovery_adapter_selector_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl ServiceDiscoveryAdapterSelectorImpl {
#[async_trait]
impl ServiceDiscoveryAdapterSelector for ServiceDiscoveryAdapterSelectorImpl {
/// Registers a `ServiceDiscoveryAdapter` with this selector
///
///
/// # Arguments
/// - `adapter`: the adapter to register
fn register(
Expand All @@ -48,13 +48,18 @@ impl ServiceDiscoveryAdapterSelector for ServiceDiscoveryAdapterSelectorImpl {
/// - `id`: the service identifier
async fn get_service_uri(&self, id: &String) -> Result<String, ServiceDiscoveryAdapterError> {
for adapter in self.adapters.iter() {
log::debug!("Attempting to discover uri for service {id} from adapter {}...", adapter.get_adapter_name());
log::debug!(
"Attempting to discover uri for service {id} from adapter {}...",
adapter.get_adapter_name()
);
match adapter.get_service_uri(id).await {
Ok(uri) => {
log::debug!("Discovered uri for service {id}");
return Ok(uri)
},
Err(e) => log::debug!("Failed to discover service uri: {e:?}. Trying next adapter...")
return Ok(uri);
}
Err(e) => {
log::debug!("Failed to discover service uri: {e:?}. Trying next adapter...")
}
}
}

Expand Down

0 comments on commit 1a56c0e

Please sign in to comment.