Skip to content

Commit

Permalink
style: 🎨 fix format lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Forsworns committed Dec 12, 2023
1 parent 4deecf4 commit ba03a9e
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions sentinel-core/src/datasource/adapters/ds_apollo.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::*;
use crate::{logging, utils::sleep_for_ms};
use apollo_client::conf::{requests::WatchRequest, ApolloConfClient};
use futures_util::{future, pin_mut, stream::StreamExt};
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};
use futures_util::{future, pin_mut, stream::StreamExt};

pub struct ApolloDatasource<P: SentinelRule + PartialEq + DeserializeOwned, H: PropertyHandler<P>> {
ds: DataSourceBase<P, H>,
Expand All @@ -16,8 +16,12 @@ pub struct ApolloDatasource<P: SentinelRule + PartialEq + DeserializeOwned, H: P
}

impl<P: SentinelRule + PartialEq + DeserializeOwned, H: PropertyHandler<P>> ApolloDatasource<P, H> {
pub fn new(client: ApolloConfClient, property: String, watch_request: WatchRequest,
handlers: Vec<Arc<H>>) -> Self {
pub fn new(
client: ApolloConfClient,
property: String,
watch_request: WatchRequest,
handlers: Vec<Arc<H>>,
) -> Self {
let mut ds = DataSourceBase::default();
for h in handlers {
ds.add_property_handler(h);
Expand All @@ -41,8 +45,10 @@ impl<P: SentinelRule + PartialEq + DeserializeOwned, H: PropertyHandler<P>> Apol
self.property
);

let stream = self.client.watch(self.watch_request.clone())
.take_while(|_| future::ready(!self.closed.load(Ordering::SeqCst)));
let stream = self
.client
.watch(self.watch_request.clone())
.take_while(|_| future::ready(!self.closed.load(Ordering::SeqCst)));

pin_mut!(stream);

Expand All @@ -58,11 +64,14 @@ impl<P: SentinelRule + PartialEq + DeserializeOwned, H: PropertyHandler<P>> Apol
if let Err(e) = self.ds.update(rule) {
logging::error!("[Apollo] Failed to update rules, {:?}", e);
}
},
Err(e) => logging::error!("[Apollo] Fail to fetch response from apollo, {:?}", e),
}
Err(e) => logging::error!(
"[Apollo] Fail to fetch response from apollo, {:?}",
e
),
};
}
},
}
// retry
Err(e) => {
logging::error!("[Apollo] Client yield an error, {:?}", e);
Expand All @@ -85,9 +94,9 @@ impl<P: SentinelRule + PartialEq + DeserializeOwned, H: PropertyHandler<P>> Apol
}

impl<P: SentinelRule + PartialEq + DeserializeOwned, H: PropertyHandler<P>> DataSource<P, H>
for ApolloDatasource<P, H>
for ApolloDatasource<P, H>
{
fn get_base(&mut self) -> &mut DataSourceBase<P, H> {
&mut self.ds
}
}
}

0 comments on commit ba03a9e

Please sign in to comment.