Skip to content

Remove expect for metadata call #12

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
33 changes: 19 additions & 14 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,16 @@ impl Observer {
let difference = Instant::now().duration_since(self.last_update_time);

if self.get_fetch_interval().as_secs() > 0 && difference > self.get_fetch_interval() {
self.last_results = self.update_current_status();
self.last_update_time = Instant::now();
match self.update_current_status() {
Ok(results) => {
self.last_results = results;
self.last_update_time = Instant::now();
},
Err(text) => {
error!("{}", text);
}
}

}
}

Expand Down Expand Up @@ -494,7 +502,7 @@ impl Observer {
)
}

pub fn update_current_status(&self) -> HashMap<String, (i64, i64)> {
pub fn update_current_status(&self) -> Result<HashMap<String, (i64, i64)>, String> {

let mut results: HashMap<String, (i64, i64)> = HashMap::new();

Expand All @@ -505,17 +513,14 @@ impl Observer {
None
};

let metadata: Metadata = self
let metadata: Metadata = match self
.client
.fetch_metadata(topic, self.get_fetch_timeout())
.expect("Failed to fetch metadata");

// let groups: GroupList = self.client.fetch_group_list(None, Duration::from_secs(20)).unwrap();

// for item in groups.groups() {
// debug!("Group name: {:}", item.name());

// }
.fetch_metadata(topic, self.get_fetch_timeout()){
Ok(metadata) => metadata,
Err(_) => {
return Result::Err(String::from("Failed to fetch metadata"))
}
};

for topic in metadata.topics().iter() {
if self.topics_set.contains(topic.name()) || self.topics_set.len() == 0 {
Expand Down Expand Up @@ -609,7 +614,7 @@ impl Observer {
}
}
}
results
Ok(results)
}
}

Expand Down