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

expose store_offset and query_offset in consumer #203

Merged
merged 5 commits into from
Oct 25, 2023

Conversation

DanielePalaia
Copy link
Contributor

This closes #195

Exposes store_offset and query_offset in Consumer struct

@DanielePalaia DanielePalaia marked this pull request as draft October 13, 2023 10:18
@codecov
Copy link

codecov bot commented Oct 13, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (749db50) 88.17% compared to head (d331ac8) 88.56%.
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #203      +/-   ##
==========================================
+ Coverage   88.17%   88.56%   +0.38%     
==========================================
  Files          68       68              
  Lines        5625     5650      +25     
==========================================
+ Hits         4960     5004      +44     
+ Misses        665      646      -19     
Files Coverage Δ
src/environment.rs 78.80% <100.00%> (+0.14%) ⬆️
src/consumer.rs 79.47% <95.65%> (+6.03%) ⬆️
src/error.rs 5.88% <0.00%> (+5.88%) ⬆️

... and 8 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@DanielePalaia DanielePalaia force-pushed the store_offset_exposed branch 3 times, most recently from 0d376e4 to 52c1278 Compare October 13, 2023 15:12
@DanielePalaia DanielePalaia force-pushed the store_offset_exposed branch 2 times, most recently from 5577acf to d73ffb3 Compare October 20, 2023 14:08
@DanielePalaia DanielePalaia marked this pull request as ready for review October 23, 2023 07:38
Copy link
Member

@Gsantomaggio Gsantomaggio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add the Offset Not Found Error test case? for the query offset in case it does not exist.

@DanielePalaia
Copy link
Contributor Author

@Gsantomaggio Sure! Done!!

@Gsantomaggio
Copy link
Member

Can you add a test using a real offset coming form the chunk ?

@DanielePalaia
Copy link
Contributor Author

Done!

Copy link
Contributor

@wolf4ood wolf4ood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a minor nit :)

src/consumer.rs Outdated
Comment on lines 153 to 172
pub async fn store_offset(&self, offset: u64) -> Result<(), ConsumerStoreOffsetError> {
if self.name.is_none() {
return Err(ConsumerStoreOffsetError::NameMissing);
}

let result = self
.internal
.client
.store_offset(
self.name.clone().unwrap().as_str(),
self.internal.stream.as_str(),
offset,
)
.await;

match result {
Ok(()) => Ok(()),
Err(e) => Err(ConsumerStoreOffsetError::Client(e)),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make it a little bit shorter like this:

Suggested change
pub async fn store_offset(&self, offset: u64) -> Result<(), ConsumerStoreOffsetError> {
if self.name.is_none() {
return Err(ConsumerStoreOffsetError::NameMissing);
}
let result = self
.internal
.client
.store_offset(
self.name.clone().unwrap().as_str(),
self.internal.stream.as_str(),
offset,
)
.await;
match result {
Ok(()) => Ok(()),
Err(e) => Err(ConsumerStoreOffsetError::Client(e)),
}
}
pub async fn store_offset(&self, offset: u64) -> Result<(), ConsumerStoreOffsetError> {
if let Some(name) = &self.name {
self.internal
.client
.store_offset(name, self.internal.stream.as_str(), offset)
.await
.map(Ok)?
} else {
Err(ConsumerStoreOffsetError::NameMissing)
}
}

same for query_offset.

@DanielePalaia
Copy link
Contributor Author

@Gsantomaggio and @wolf4ood for the review! I also implemented the last suggestion as having more compact code is better!

@DanielePalaia DanielePalaia merged commit 277aebb into main Oct 25, 2023
@DanielePalaia DanielePalaia deleted the store_offset_exposed branch October 25, 2023 16:54
@github-actions github-actions bot mentioned this pull request Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose the store_offset feature to the Consumer struct
3 participants