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

[NIT-2868] Allow pubsub interface to return an error #2753

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

amsanghi
Copy link
Contributor

Fixes: NIT-2868

@cla-bot cla-bot bot added the s Automatically added by the CLA bot if the creator of a PR is registered as having signed the CLA. label Oct 24, 2024
@amsanghi amsanghi marked this pull request as ready for review October 28, 2024 15:04
errorKey := ErrorKeyFor(c.StreamName(), messageID)
log.Debug("consumer: setting error", "cid", c.id, "msgIdInStream", messageID, "errorKeyInRedis", errorKey)
acquired, err := c.client.SetNX(ctx, errorKey, resp, c.cfg.ResponseEntryTimeout).Result()
if err != nil || !acquired {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we return a predefined error if !acquired?
e.g.

var AlreadySetError = errors.New("redis key already set")
...
func SetError() {
    ...
    if !acquired && err == nil {
        err = AlreadySetError
    }
    if err != nil {
	return fmt.Errorf("setting error for message with message-id in stream: %v, error: %w", messageID, err)
    }
    ...
}

and then SetError caller would be able to check returned error against this error and know if SetError failed because of some real error or because of some other consumer setting the key first.

That will be useful, e.g. when we'll want to call SetError for a message that was retried too many times, so we could only print an error log when there is real error and not when another customer set the error first.

And also it should be nicer to log
"setting error for message with message-id in stream: %v, error: redis key already set" instead of
"setting error for message with message-id in stream: %v, error: nil"

We can also add a similar error in SetResult method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s Automatically added by the CLA bot if the creator of a PR is registered as having signed the CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants