Skip to content

feat: Improve error handling and logging in Redis worker #31

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: main
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
17 changes: 15 additions & 2 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package redisdb
import (
"context"
"encoding/json"
"errors"
"fmt"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -83,7 +85,11 @@ func (w *Worker) startConsumer() {
w.opts.group,
"$",
).Err(); err != nil {
w.opts.logger.Error(err)
if err.Error() == "BUSYGROUP Consumer Group name already exists" {
w.opts.logger.Info(err)
} else {
w.opts.logger.Error(err)
}
}

go w.fetchTask()
Expand All @@ -110,7 +116,14 @@ func (w *Worker) fetchTask() {
Block: w.opts.blockTime,
}).Result()
if err != nil {
w.opts.logger.Errorf("error while reading from redis %v", err)
workerInfo := fmt.Sprintf("{streamName: %q, group: %q, consumer: %q}",
w.opts.streamName, w.opts.group, w.opts.consumer)
if errors.Is(err, redis.Nil) {
w.opts.logger.Infof("no data while reading from redis stream %s", workerInfo)
} else {
w.opts.logger.Errorf("error while reading from redis %s %v", workerInfo, err)
}

continue
}
// we have received the data we should loop it and queue the messages
Expand Down