Skip to content
Merged
Show file tree
Hide file tree
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
15 changes: 12 additions & 3 deletions internal/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package consumer

import (
"context"
"log"

"github.com/hookdeck/outpost/internal/logging"
"github.com/hookdeck/outpost/internal/mqs"
"go.opentelemetry.io/otel"
"go.uber.org/zap"
)

type Consumer interface {
Expand All @@ -19,6 +20,7 @@ type MessageHandler interface {
type consumerImplOptions struct {
name string
concurrency int
logger *logging.Logger
}

func WithName(name string) func(*consumerImplOptions) {
Expand All @@ -33,6 +35,12 @@ func WithConcurrency(concurrency int) func(*consumerImplOptions) {
}
}

func WithLogger(logger *logging.Logger) func(*consumerImplOptions) {
return func(c *consumerImplOptions) {
c.logger = logger
}
}

func New(subscription mqs.Subscription, handler MessageHandler, opts ...func(*consumerImplOptions)) Consumer {
options := &consumerImplOptions{
name: "",
Expand Down Expand Up @@ -86,10 +94,11 @@ recvLoop:
defer span.End()

err = c.handler.Handle(handlerCtx, msg)
// TODO: error handling?
if err != nil {
span.RecordError(err)
log.Printf("consumer handler error: %v", err)
if c.logger != nil {
c.logger.Ctx(handlerCtx).Error("consumer handler error", zap.String("name", c.name), zap.Error(err))
}
}
}()
}
Expand Down
1 change: 1 addition & 0 deletions internal/services/consumer_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (w *ConsumerWorker) Run(ctx context.Context) error {
csm := consumer.New(subscription, w.handler,
consumer.WithName(w.name),
consumer.WithConcurrency(w.concurrency),
consumer.WithLogger(w.logger),
)

if err := csm.Run(ctx); err != nil {
Expand Down
Loading