Skip to content

Proposal for fix for loss of relation between message and ack_id.#15

Merged
kayleg merged 3 commits intokayleg:masterfrom
olofwalker:fix-for-get-messages
Oct 22, 2021
Merged

Proposal for fix for loss of relation between message and ack_id.#15
kayleg merged 3 commits intokayleg:masterfrom
olofwalker:fix-for-get-messages

Conversation

@olofwalker
Copy link
Contributor

This PR attempts a fix for #14

This changes the returned values from get_messages from a tuple of vectors with ack_ids and message to a HashMap where ack_id is the key of a Result that contains either the successfully deserialized message or the error that occurred.

@hseeberger
Copy link
Contributor

@kayleg may I kindly ask whether you already had time to consider this PR?

@kayleg
Copy link
Owner

kayleg commented Sep 28, 2021

Apologies for the delay - thanks for adding this.

My one question is: Do we like having to check each message for an error?

I personally like just being able to operate over the results without the needed boilerplate of

if let Ok(m) = someResult 

but without having each entry as a result we can't correctly handle invalid input.

@olofwalker and @hseeberger
Let me know your thoughts. I'll merge it in if we're happy with the resulting interface.

@hseeberger
Copy link
Contributor

Thanks for getting back so quickly. Unfortunately I do not fully understand your question. So let me explain what we need: after pulling a message from Pub/Sub, we apply further processing which might fail or not. Therefore we need to know exactly which ack_id is associated with a particular message. That is the essence of this PR. Whether we use a HashMap from ack_id to message or vice versa or a vector of tuples does not matter that much. Actually one might argue that we should switch to a vector of tuples, because we do not use any of the HashMap features.

Does that answer your question?

@hseeberger
Copy link
Contributor

After some more thinking I guess I know understand your question. As it is unclear whether users want to acknowledge Pub/Sub messages which could not get deserialized or not, I think we must return all results with their associated ack_ids. For our use case it would be fine to filter out the errors and only return all successfully deserialized messages with their ack_ids, but that is just our current use case.

Nevertheless I think that according to the principle of least power we should not return a HashMap but a Vec<(String, Result<T, error::Error>)> instead. Or maybe better flip the tuple:

pub async fn get_messages<T: FromPubSubMessage>(&self) -> 
    Result<Vec<(Result<T, error::Error>, String)>, error::Error> { ... }

@kayleg
Copy link
Owner

kayleg commented Sep 28, 2021

I like your last point, we're not using any features provided by the HashMap so let's just return the vec of tuples.

hseeberger and others added 3 commits September 29, 2021 20:56
* This fix changes the returned values from `get_messages` from a tuple of
vectors with ack_ids and message, to a HashMap where ack_id is stored
with a Result that contains either the successfully deserialized message
or the error that occurred.

Co-authored-by: Robert Walker <robert@walker.st>
vectors with ack_ids and message, to a HashMap where ack_id is stored
with a Result that contains either the successfully deserialized message
or the error that occured.
@hseeberger
Copy link
Contributor

Hey @kayleg, it would be great if you could review this again.

Copy link
Owner

@kayleg kayleg left a comment

Choose a reason for hiding this comment

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

LGTM - Thanks folks. I'll cut a new release including this.

@kayleg kayleg merged commit 83b6cc4 into kayleg:master Oct 22, 2021
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.

3 participants