From 919422f139410bee043baa08bfc9ec4156dfc228 Mon Sep 17 00:00:00 2001 From: Christian Carlsson Date: Mon, 16 Dec 2024 12:46:17 +0000 Subject: [PATCH] feat: don't fail publish event (#231) --- server/bus/bus.go | 9 +++------ server/pkg/trace/trace.go | 6 ++---- server/rpc/v1/user.go | 7 ++----- server/rpc/v1/workout.go | 7 ++----- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/server/bus/bus.go b/server/bus/bus.go index 0c6ecec5..1e2b924b 100644 --- a/server/bus/bus.go +++ b/server/bus/bus.go @@ -24,20 +24,17 @@ func New(log *zap.Logger) *Bus { } } -var errChannelNotFound = fmt.Errorf("channel not found for event") - -func (b *Bus) Publish(event string, payload any) error { +func (b *Bus) Publish(event string, payload any) { b.mu.RLock() channel, found := b.channels[event] b.mu.RUnlock() if !found { - // TODO: Log error and return. - return fmt.Errorf("%w: %s", errChannelNotFound, event) + b.log.Error("channel not found", zap.String("event", event)) + return } channel <- payload - return nil } const ( diff --git a/server/pkg/trace/trace.go b/server/pkg/trace/trace.go index 93da6ade..4882cb7a 100644 --- a/server/pkg/trace/trace.go +++ b/server/pkg/trace/trace.go @@ -40,13 +40,11 @@ func (m *Tracer) Trace(uri string) *Trace { start: time.Now().UTC(), onEnd: func(duration time.Duration, statusCode int) { m.log.Info("trace", zap.String("uri", uri), zap.Duration("duration", duration), zap.Int("status_code", statusCode)) - if err := m.bus.Publish(events.RequestTraced, &payloads.RequestTraced{ + m.bus.Publish(events.RequestTraced, &payloads.RequestTraced{ Request: uri, DurationMS: int(duration.Milliseconds()), StatusCode: statusCode, - }); err != nil { - m.log.Error("publishing trace event failed", zap.Error(err)) - } + }) }, } } diff --git a/server/rpc/v1/user.go b/server/rpc/v1/user.go index f67b055d..e7ba6845 100644 --- a/server/rpc/v1/user.go +++ b/server/rpc/v1/user.go @@ -98,13 +98,10 @@ func (h *userHandler) FollowUser(ctx context.Context, req *connect.Request[v1.Fo return nil, connect.NewError(connect.CodeInternal, nil) } - if err := h.bus.Publish(events.UserFollowed, &payloads.UserFollowed{ + h.bus.Publish(events.UserFollowed, &payloads.UserFollowed{ FollowerID: userID, FolloweeID: req.Msg.GetFollowId(), - }); err != nil { - log.Error("failed to publish user followed event", zap.Error(err)) - return nil, connect.NewError(connect.CodeInternal, nil) - } + }) return &connect.Response[v1.FollowUserResponse]{ Msg: &v1.FollowUserResponse{}, diff --git a/server/rpc/v1/workout.go b/server/rpc/v1/workout.go index 03ef6538..e625336e 100644 --- a/server/rpc/v1/workout.go +++ b/server/rpc/v1/workout.go @@ -227,12 +227,9 @@ func (h *workoutHandler) PostComment(ctx context.Context, req *connect.Request[v return nil, connect.NewError(connect.CodeInternal, nil) } - if err = h.bus.Publish(events.WorkoutCommentPosted, &payloads.WorkoutCommentPosted{ + h.bus.Publish(events.WorkoutCommentPosted, &payloads.WorkoutCommentPosted{ CommentID: comment.ID, - }); err != nil { - log.Error("failed to publish event", zap.Error(err)) - return nil, connect.NewError(connect.CodeInternal, nil) - } + }) log.Info("workout comment posted") return &connect.Response[v1.PostCommentResponse]{